ahzulfi Posted March 8, 2008 Share Posted March 8, 2008 Hello, i want to get $variable = 'sometext'; from PHP to javascript. i have declared $variable in PHP i m calling javascript as <script type='javascript' src ='file.js'> in my page, but dont know how to send $variable to javascript so that i can use it in javascript. hope you got what i m asking. Urgently needed. Thanks ArslanHassan Quote Link to comment Share on other sites More sharing options...
mainewoods Posted March 8, 2008 Share Posted March 8, 2008 just echo it out inside of the javascript. the jsvariable could then be used in file.js if you want. <script type="text/javascript"> var jsvariable = "<?php echo $phpvariable; ?>"; </script> <script type='javascript' src ='file.js'></script> Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted March 9, 2008 Share Posted March 9, 2008 Im not sure if this is possible, it is merely a suggestion/idea <script type='javascript' src ='file.js?myVariable=<?php echo $phpvariable; ?>'></script> Quote Link to comment Share on other sites More sharing options...
ahzulfi Posted March 9, 2008 Author Share Posted March 9, 2008 just echo it out inside of the javascript. the jsvariable could then be used in file.js if you want. <script type="text/javascript"> var jsvariable = "<?php echo $phpvariable; ?>"; </script> <script type='javascript' src ='file.js'></script> :D :D WORKED ;D THANKS ALOT 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.