How to convert Javascript variable to PHP

Discussion in 'Programming' started by chathura87, Sep 4, 2011.

  1. #1
    Hi, i know who to convert PHP variable to Javascript!!

    But does anyone know how to convert viceversa Means Jaavascript variable to PHP!!
     
    chathura87, Sep 4, 2011 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    You don't "convert" it. The Javascript variable exists in the web browser. PHP runs on the server. You send the Javascript variable to the PHP file using AJAX. If the Javascript code needs something back from the PHP file, the PHP file echoes it.
     
    Rukbat, Sep 4, 2011 IP
  3. MayurGondaliya

    MayurGondaliya Well-Known Member

    Messages:
    1,233
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    170
    #3
    We can not say it conversion. Instead we can call it a tweak to copy the value of PHP variable to the Javascript variable.

    
    <script>
    var myvar = <?php echo $phpvariable; ?>
    </script>
    
    Code (markup):

    Javascript variable can be copied to the PHP variable using AJAX calls. But, it will be the complex as you may need to split your page to a few partial parts that all individually load using AJAX, depending on your application. could you let us know what you are trying to achieve using JS to PHP variable copy?
     
    MayurGondaliya, Sep 5, 2011 IP