noahwilson Posted May 9, 2013 Share Posted May 9, 2013 Hello Gusy,<script> var id=`$`php; </script> i have add php variable store as JavaScript. but some thing wrong in my code. what wrong with there please help me . Thanks Quote Link to comment https://forums.phpfreaks.com/topic/277829-how-to-php-variable-value-assign-as-java-script/ Share on other sites More sharing options...
PravinS Posted May 9, 2013 Share Posted May 9, 2013 Use like this <script language="javascript" type="text/javascript"> var id = '<?php echo $id; ?>'; </script> Quote Link to comment https://forums.phpfreaks.com/topic/277829-how-to-php-variable-value-assign-as-java-script/#findComment-1429272 Share on other sites More sharing options...
requinix Posted May 9, 2013 Share Posted May 9, 2013 Even safer is <script type="text/javascript"> var id = <?= json_encode($id) ?>; </script>(language=javascript has been deprecated for a long time) Quote Link to comment https://forums.phpfreaks.com/topic/277829-how-to-php-variable-value-assign-as-java-script/#findComment-1429336 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.