Jump to content

pass a varible from php to javascript


xbl1

Recommended Posts

Hi;i am trying to pass a varible from php to javascript, but it does not work. i could print out the value of Could you help me, please.i could print out the value of $test from the following:

<?php $test=" me "; ?><script type="text/javascript"> function myTest(){ alert(" this is " + <?php $test; ?>); }</script><input type="button" id="b3" name="b3" value="3" onClick="myTest()" />
Link to comment
Share on other sites

alert(" this is <?php echo $test; ?>");PHP generates Javascript (or HTML, or whatever you want) code. Javascript does have access to PHP variables, but when PHP runs it will insert the value of that variable into the Javascript code. If you run the page then view the source code, you'll see what I mean.

Link to comment
Share on other sites

alert(" this is <?php echo $test; ?>");PHP generates Javascript (or HTML, or whatever you want) code. Javascript does have access to PHP variables, but when PHP runs it will insert the value of that variable into the Javascript code. If you run the page then view the source code, you'll see what I mean.
thanks for a lot, it does work.
Link to comment
Share on other sites

alert(" this is <?php echo $test; ?>");PHP generates Javascript (or HTML, or whatever you want) code. Javascript does have access to PHP variables, but when PHP runs it will insert the value of that variable into the Javascript code. If you run the page then view the source code, you'll see what I mean.
thanks for a lot, it does work.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...