passing values from php to javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muthusamy
    New Member
    • Mar 2007
    • 1

    passing values from php to javascript

    Hi,
    I am R. Muthusamy

    Please give the decriptions for following question
    1. How to be pass the values from php to java script.
    2. how to be pass the php values to javascript.



    Thank You,
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Question 1 and 2 are identical.

    The following sample stores a value of php variable $v in an HTML input field. When the button is clicked, a JS routine is invoked that extract the value and issues an alert message.

    Code:
    <script type="text/javascript">
    function passIt() {
      var myvalue = document.getElementById("q").value;
      alert('myvalue='+myvalue);
    }
    </script>
    <?php
    $v = "This is my value";
    ?>
    <input name='q' value='<?php echo $v ?>' />
    <input type="submit" value="Pass to JS" onclick="passIt()" />
    Ronald :cool:

    Comment

    Working...