Pig Posted August 31, 2009 Share Posted August 31, 2009 Hi all I am trying to pass a php variable, we shall call $x to the JS array below. <script type="text/javascript"> var price = Array(); var setup = Array(); price['92342257765'] = '15'; price['92342257734'] = '20'; price['92342257778'] = '25'; price['92342258706'] = '30'; price['92342258732'] = '35'; price['92342258700'] = '40'; price['92342258745'] = '45'; price['92342258736'] = '9'; price['92342258697'] = 'xx'; //replace xx with $x php variable. </script> I am looking to replace the xx, with our $x php variable? Anyone know how I can do this? Thanks. [code][code] [/code][/code] Quote Link to comment https://forums.phpfreaks.com/topic/172603-passing-php-variable-to-javascript/ Share on other sites More sharing options...
ignace Posted August 31, 2009 Share Posted August 31, 2009 <script type="text/javascript"> var price = Array(); var setup = Array(); price['92342257765'] = '15'; price['92342257734'] = '20'; price['92342257778'] = '25'; price['92342258706'] = '30'; price['92342258732'] = '35'; price['92342258700'] = '40'; price['92342258745'] = '45'; price['92342258736'] = '9'; price['92342258697'] = '<?php print $x; ?>'; //replace xx with $x php variable. </script> Quote Link to comment https://forums.phpfreaks.com/topic/172603-passing-php-variable-to-javascript/#findComment-909846 Share on other sites More sharing options...
mikesta707 Posted August 31, 2009 Share Posted August 31, 2009 echo "<script type='text/javascript'> price['92342258697'] = '".$myvar."';\n </script>"; oh beaten to the punch. oh well Quote Link to comment https://forums.phpfreaks.com/topic/172603-passing-php-variable-to-javascript/#findComment-909847 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.