store value of input type="hidden" into a php variable.
The value is set by javascript into a hidden variable[input].
Now i need to save its value into a $myphpvariable.
I cant set the value into session with javascript and cookies is not an option.
After the page is submitted, hidden input elements will show up in the $_POST
superglobal, just like any other form element. If the hidden form field were called coolsecret
then the value would be in $_POST['coolsecret']
(or $_GET['coolsecret']
if you used method=get
).
Before the page is submitted, there's no way to get a value from javascript into PHP, because your PHP code is all executed on the server, and the javascript isn't executed until the user has loaded the page on their computer. You should think about what you're trying to accomplish, and whether there's any way to compute the variable you want in PHP instead. If it's absolutely impossible to compute the variable ahead of time, then like Another Code said, you'll need to use something like an AJAX request.
What do you mean by save? When you submit that form you will be having value of hidden variable in $_POST
or $_GET
depending on the method
of form
You store php variable in js.but u cant stored js variable into php variable .because php run at server side and javescript at client side
The only ways to communicate Javascript results to a server-side script are:
You can't just mix the two, since Javascript operates inside the browser and PHP executes before a page is even sent to the browser.
Post it to the server then use $_POST["the_id"]
to get its value.