/    Sign up×
Community /Pin to ProfileBookmark

Getting Javascript variable to php

How do I get a javascript variable and pass it into a php variable???

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@aaronbdavisApr 17.2006 — user javascript to set the value of a hidden input element. Then collect it with PHP using the $_GET or $_POST array (depending on which you are using for the form)
Copy linkTweet thisAlerts:
@tenniskid493authorApr 17.2006 — just to make sure I understand...so like put the value into a text area and then turn the style.display of the text area to 'none' and then retrieve it using php???
Copy linkTweet thisAlerts:
@aaronbdavisApr 17.2006 — You don't need to use a textara. Use a hidden input element instead. i.e.[code=html]<form id="myForm" method="post">

...

<input type="hidden" id="myHiddenField" name="myHiddenField" />

...

</form>[/code]


then set the value with JS [CODE]var e = document.getElementById('myHiddenField');
e.value = "what ever I like"; //change as needed[/CODE]


Then, when you submit the form, you can collect the value thusly:[code=php]$myVar = $_POST['myHiddenField'];[/code]
Copy linkTweet thisAlerts:
@tenniskid493authorApr 17.2006 — ok..thank you
Copy linkTweet thisAlerts:
@bokehApr 17.2006 — Or like this:
[code=php]onEvent =
"url='http://location.com/dir/file.php';
myVariable='value';
window.location=url+'?phpname='+myVariable"[/code]
Copy linkTweet thisAlerts:
@tenniskid493authorApr 17.2006 — ok..this sort of goes along w/ this. I'm a complete n00b at php so I can barely figure anything out. If I need to make a registration page where someone needs to enter their desired username, desired password, and email address, how would I make this page using HTML and then have a submit button taht then passes all these values into PHP to eventually be stored in a mysql database. Any help, links to tutorials, or advice would be greatly appreciated. Sorry for not offering a start at a code, but I'm completly confused one even how to start this.
×

Success!

Help @tenniskid493 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...