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.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!