bplogan Posted January 16, 2008 Share Posted January 16, 2008 Need help passing php vairable to javascript array. I have three php variables. $one, $two, and $three. They each contain text. I need to get these variables into a javascript array. This is what I am trying below, but the array does not get these values. Any help would be appreciated. var fcontent=new Array(); fcontent[0]= <?php print $one; ?>; fcontent[1]= <?php print $two; ?>; fcontent[2]= <?php print $three; ?>; Quote Link to comment https://forums.phpfreaks.com/topic/86370-solved-need-help-passing-php-vairable-to-javascript-array/ Share on other sites More sharing options...
interpim Posted January 16, 2008 Share Posted January 16, 2008 try var fcontent=new Array(); fcontent[0]= <?php echo $one; ?>; fcontent[1]= <?php echo $two; ?>; fcontent[2]= <?php echo $three; ?>; Quote Link to comment https://forums.phpfreaks.com/topic/86370-solved-need-help-passing-php-vairable-to-javascript-array/#findComment-441342 Share on other sites More sharing options...
bplogan Posted January 16, 2008 Author Share Posted January 16, 2008 Thanks for the reply, but it didn't work. When the page loads, I get the "done but with errors" exclamation mark in the IE window. If I just put text for each of the array items, it works. Here is more code: <script type="text/javascript"> var delay = 2000; var maxsteps=30; var stepdelay=40; var startcolor= new Array(255,255,255); var endcolor=new Array(0,0,0); var fcontent=new Array(); begintag='<div style="font: normal 14px Arial; padding: 5px;">'; fcontent[0]= <?php echo $one; ?>; fcontent[1]= <?php echo $two; ?>; fcontent[2]= <?php echo $three; ?>; closetag='</div>'; Quote Link to comment https://forums.phpfreaks.com/topic/86370-solved-need-help-passing-php-vairable-to-javascript-array/#findComment-441344 Share on other sites More sharing options...
interpim Posted January 16, 2008 Share Posted January 16, 2008 where are these php variables coming from? Quote Link to comment https://forums.phpfreaks.com/topic/86370-solved-need-help-passing-php-vairable-to-javascript-array/#findComment-441348 Share on other sites More sharing options...
bplogan Posted January 16, 2008 Author Share Posted January 16, 2008 I got it, thanks for the help though. I needed quotes around the php. like this: fcontent[0]= "<?php echo $one; ?>"; fcontent[1]= "<?php echo $two; ?>"; fcontent[2]= "<?php echo $three; ?>"; Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/86370-solved-need-help-passing-php-vairable-to-javascript-array/#findComment-441351 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.