Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign the javascript variable value to php variable [duplicate]

Tags:

javascript

php

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......

like image 436
Muhammad Usman Avatar asked Dec 17 '22 01:12

Muhammad Usman


1 Answers

PHP is executed before javascript. You can't do that. PHP is server based, JavaScript is client based.

When PHP is finished executing, it outputs HTML. In the HTML there can be JavaScript code also. So PHP can 'control' JavaScript by outputting JavaScript code to the page, but not the other way around. You'd have to use Ajax-call for that.

like image 154
Simon Forsberg Avatar answered Jan 04 '23 23:01

Simon Forsberg