Skip to content Skip to sidebar Skip to footer

How Can I Pass Js Variable To Php Variable?

here is my sample code hope you can help me. how can i pass a JavaScript variable to php variable?

Solution 1:

You can't. As others said million times, JavaScript is Client Side Language meanwhile PHP is Server Side. You can't manipulate Server Side language via Client Side Language. You should pass your JavaScript variable to Server with AJAX and do your operation.

Sources that you can find useful :

Access a JavaScript variable from PHP

How to pass variables and data from PHP to JavaScript?


Solution 2:

<script>
    var jsvar = "Name";
</script>

<?php
    $phpVar = "<script>document.write(jsvar);</script>";
    echo $phpVar;
?>

Post a Comment for "How Can I Pass Js Variable To Php Variable?"