Jump to content

Echo PHP variable in JavaScript


beennn

Recommended Posts

Here's what I've tried:

	  <script>		   <? for ($i = 0; $i < sizeof($result_array); $i++) { ?>	  		document.write('<? echo $i ?>');	  	   <? } ?>		  </script>

and

	   <script>		   <? for ($i = 0; $i < sizeof($result_array); $i++) { ?>	  		document.write('<? $i ?>');	  	   <? } ?>		  </script>

I've also tried just using JavaScript with the PHP variable embedded but still not luck. Any ideas? EDIT: Turns out I just needed to use <?php instead of <?

Edited by beennn
Link to comment
Share on other sites

this will work

$str = $_SESSION['first_10_flag'];echo '<script type="text/javascript">';echo 'alert("' . $str . '");';echo '</script>';

w/ the php tags

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
×
×
  • Create New...