d.shankar Posted November 7, 2007 Share Posted November 7, 2007 I am unable to pass my php parameter to the javascript. But it is not getting fetched. <?php $str="from php"; ?> <script> var abc="<?php echo($str) ?>" alert(abc); </script> <?php ?> Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted November 7, 2007 Share Posted November 7, 2007 perhaps maybe use this <script type="text/javascript"> ????? Quote Link to comment Share on other sites More sharing options...
NArc0t1c Posted November 7, 2007 Share Posted November 7, 2007 Try: <?php $str = "from php"; ?> <script> abc = "<?=$str?>" alert(abc); </script> <?php //other code ?> Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2007 Share Posted November 7, 2007 you missed out the semi-colin <?php $str="from php"; ?> <script> var abc="<?php echo($str) ?>"; alert(abc); </script> <?php ?> Quote Link to comment Share on other sites More sharing options...
NArc0t1c Posted November 7, 2007 Share Posted November 7, 2007 you missed out the semi-colin <?php $str="from php"; ?> <script> var abc="<?php echo($str) ?>"; alert(abc); </script> <?php ?> Many programmers continue this habit when writing JavaScript, but in general, semicolons are optional! However, semicolons are required if you want to put more than one statement on a single line. Quote Link to comment Share on other sites More sharing options...
d.shankar Posted November 7, 2007 Author Share Posted November 7, 2007 Thanks a lot guys ! Semicolons are not neccesary in JS. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted November 7, 2007 Share Posted November 7, 2007 In php!!! <script type="text/javascript"> var abc="<?php echo($str); ?>"; alert(abc); </script> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.