xbl1 Posted September 27, 2007 Share Posted September 27, 2007 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 More sharing options...
justsomeguy Posted September 27, 2007 Share Posted September 27, 2007 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 More sharing options...
xbl1 Posted September 28, 2007 Author Share Posted September 28, 2007 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 More sharing options...
xbl1 Posted September 28, 2007 Author Share Posted September 28, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.