Jump to content

pass a varible from php to javascript


xbl1
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...