Passing JavaScript variable to PHP

Passing JavaScript variable to PHP


In my program, radio button pressed will open its corresponding dropdown list (for example: the button ‘Asia’ will open China, Japan and India).
 
The variable ‘x’ below detects the selected radio button and I need to pass its value inside my JavaScript to a PHP (to open the corresponding list):

  1. <script>
      var x = 123;
      <?php $what_is_myVar = x ; ?>
    </script>



 

The following code is successfully passing the variable ‘x’ to PHP, but this is done outside JavaScript:

  1. <head>
    <script type="text/javascript">
      function passVariable(){
            var x = '123';
     
            // get the current url and append variable
            var url = document.location.href + '?x=' + x;
     
            // to prevent looping
            var exists = document.location.href.indexOf('?x=');
            









  2.         if(exists < 0){
                  // redirect passing variable
                  window.location = url;
            }
      }
    </script>
    </head>





  3. <body onload="passVariable()">
      <?php echo $_REQUEST['x']; ?>
    </body>

 

Please anyone can help me with an idea, using my code or Jquery, to pass inside JavaScript the value of 'x' into $what_is_myVar

 

Thanks for any reply,