I need to pass js variavle to php part at this code:
<script type="text/javascript>
var x=32;
</script>
<?
echo $x;
?>
I want to use x value at php. How to do that?? is there any way without reloading the page?
I need to pass js variavle to php part at this code:
I want to use x value at php. How to do that?? is there any way without reloading the page? |
|||
|
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.
You can't do that. PHP code has already finished processing by the time the page gets to the browser. It's too late for Javascript to affect it. |
|||
|
Actually you can not do this. PHP runs on server, JS runs on client machine.
Then in PHP you can get it:
|
|||
using jquery is the easy way
|
|||
|
You can do it by using AJAX to pass the request to the server. You'll need the jQuery get method to do that. Like:
And use it in the PHP code as:
|
|||
|