Is it possible to use JavaScript's variable in PHP? [duplicate]
Possible Duplicate:
Access a JavaScript variable from PHP
theVariable = String.fromCharCode(theVariable).toLowerCase();
is it possible to use theVariable in PHP codes ? How?
Not really... you can send it to a PHP script using AJAX or an HTML form. I strongly recommend you get a clearer understanding of what JavaScript is vs. PHP, particularly what it means that JavaScript runs on the client-side (i.e. in the browser), and PHP runs server-side.
Only if the the variable is sent via ajax to a PHP page. You see PHP is executed first, then the page is served to the client. Then the client executes the javascript. So the javascript is executed long after the PHP has been executed.
To use a variable that is in JavaScript in PHP, you have to send an Ajax request to a PHP page passing that variable in. This probably isn't the effect you're looking for.
JavaScript executes on the viewer's computer. PHP executes on the server. To send a JavaScript variable to PHP, you need to send some packet of information from the client to the server. This is done as a GET/POST request.
The only way to pass a variable from JavaScript to PHP is to pass it by an AJAX call.
精彩评论