Is it Possible To Transfer Data From Php Variable To Javascript Variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samiul
    New Member
    • Sep 2007
    • 1

    Is it Possible To Transfer Data From Php Variable To Javascript Variable

    HI,
    Here is a question that is , is it ever possible to pass data from PHP variable to Javascript variable? if yes then please let me know and if not why? I think it is possible...
    Samiul haque
  • gregerly
    Recognized Expert New Member
    • Sep 2006
    • 192

    #2
    Originally posted by samiul
    HI,
    Here is a question that is , is it ever possible to pass data from PHP variable to Javascript variable? if yes then please let me know and if not why? I think it is possible...
    Samiul haque
    Yes you can. Given:

    [PHP]<?
    $myVar = "someVal";
    ?>[/PHP]

    You could then do this:

    [CODE=Javascript]<script type='text/javascript'>
    var el = document.getEle mentById('<?=$m yVar; ?>');
    </script>[/CODE]

    Notice the $myVar variable being echoed inside the javascript.

    Hope that helps.

    Greg

    Comment

    Working...