April 18, 2012
How to assign the javascript variable value to php variable
Question by Rana Muhammad Usman
Possible Duplicate:
How to pass JavaScript variables to PHP?
I want to assign the javascript variable to php variable
$msg = "<script>document.write(message)</script>";
$f = new FacebookPost;
$f->message = $msg;
But it is not working……
Answer by Armatus
Javascript works on the user’s computer, PHP works on your server. In order to send variables from JS to PHP and vice versa, you need communication such as a page load.
Have a look here on what you can do: How to pass javascript variables to php or more specifically the first answer (http://stackoverflow.com/a/1917626/1311593)
Answer by Starx
Javascript, is a client side script, Where as PHP
is a server side script.
The only way you can send data to PHP is through redirection
or ajax
.