PHP: document.wr" /> PHP: document.wr" /> PHP: document.wr"/>

pass var jfrom JS to PHP

31 Views Asked by At

In my code the $vl var is empty. Why?

JS;

  <script>
     $(document).ready(function(e) {
     var vl = "ciao";

    });
  </script>

PHP:

  <?PHP
    $vl= "<script>document.write(vl); </script>";
     echo "bariabile:  ".$vl;
    ?>
2

There are 2 best solutions below

0
Stuart On

This simply wont work, do try to read a few more tutorials and references for both php and javascript.

0
Flex_able On

Solved:

Hs:

<script>
     $(document).ready(function(e) {
     var vl = "ciao";
     window.location.href = "TEST_YT.php?nm=" +vl;

    });
  </script>

PHP:

?PHP
$vl= "<script>document.write(vl); </script>";
 echo "bariabile:  ".$_GET['nm'];
?>