Connecting Tech Pros Worldwide Help | Site Map

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

Newbie
 
Join Date: Sep 2007
Posts: 1
#1: Sep 7 '07
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's Avatar
Expert
 
Join Date: Sep 2006
Posts: 189
#2: Sep 7 '07

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


Quote:

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:

Expand|Select|Wrap|Line Numbers
  1. <script type='text/javascript'>
  2.      var el = document.getElementById('<?=$myVar; ?>');
  3. </script>
Notice the $myVar variable being echoed inside the javascript.

Hope that helps.

Greg
Reply


Similar PHP bytes