CBR Posted October 13, 2008 Share Posted October 13, 2008 <script type="text/javascript"> Event.observe(window, 'load', function() { manualPB2 = new JS_BRAMUS.jsProgressBar( $('element6'), 85, { barImage : Array( 'images/bramus/percentImage_back4.png', 'images/bramus/percentImage_back3.png', 'images/bramus/percentImage_back2.png', 'images/bramus/percentImage_back1.png' ) } ); }, false); </script> In the above code I would like to insert an array where 85 is listed. for instance I would like to put in there the below. $arrayname = 'arraynameresult'; So putting in $arrayname where the 85 is will not work, I have tried over and over. any ideas? Link to comment https://forums.phpfreaks.com/topic/128272-inserting-an-array-in-javascript-is-this-possible/ Share on other sites More sharing options...
Acs Posted October 13, 2008 Share Posted October 13, 2008 I really don't understand what you want. Link to comment https://forums.phpfreaks.com/topic/128272-inserting-an-array-in-javascript-is-this-possible/#findComment-664381 Share on other sites More sharing options...
CBR Posted October 13, 2008 Author Share Posted October 13, 2008 Take a look at the top code. It has a place where it has an 85. I would like to get the number out of a mysql query for instance 88, and populate that new number where the 85 is. Does that make sense? This is for a progress bar that I plan to use to show status of some goals. Link to comment https://forums.phpfreaks.com/topic/128272-inserting-an-array-in-javascript-is-this-possible/#findComment-664389 Share on other sites More sharing options...
kenrbnsn Posted October 13, 2008 Share Posted October 13, 2008 If you're not in PHP there, you have to go into PHP, echo the variable and then leave PHP: <script type="text/javascript"> Event.observe(window, 'load', function() { manualPB2 = new JS_BRAMUS.jsProgressBar( $('element6'), <?php echo $arrayname ?> , { barImage : Array( 'images/bramus/percentImage_back4.png', 'images/bramus/percentImage_back3.png', 'images/bramus/percentImage_back2.png', 'images/bramus/percentImage_back1.png' ) } ); }, false); </script> Ken Link to comment https://forums.phpfreaks.com/topic/128272-inserting-an-array-in-javascript-is-this-possible/#findComment-664393 Share on other sites More sharing options...
CroNiX Posted October 13, 2008 Share Posted October 13, 2008 you need to use php tags to set javascript variables derived from php...you can't just mix them. <?php $myid = 85; ?> <script type="text/javascript"> Event.observe(window, 'load', function() { manualPB2 = new JS_BRAMUS.jsProgressBar( $('element6'), <?php echo $myid; ?>, { barImage : Array( 'images/bramus/percentImage_back4.png', 'images/bramus/percentImage_back3.png', 'images/bramus/percentImage_back2.png', 'images/bramus/percentImage_back1.png' ) } ); }, false); </script> Link to comment https://forums.phpfreaks.com/topic/128272-inserting-an-array-in-javascript-is-this-possible/#findComment-664400 Share on other sites More sharing options...
redarrow Posted October 13, 2008 Share Posted October 13, 2008 <?php $a=array("john","petter","paul"); ?> <script type="text/javascript"> Event.observe(window, 'load', function() { manualPB2 = new JS_BRAMUS.jsProgressBar( $('element6'), <?php for($i=0; $i<count($a); $i++){echo $a[$i];} ?>, { barImage : Array( 'images/bramus/percentImage_back4.png', 'images/bramus/percentImage_back3.png', 'images/bramus/percentImage_back2.png', 'images/bramus/percentImage_back1.png' ) } ); }, false); </script> Link to comment https://forums.phpfreaks.com/topic/128272-inserting-an-array-in-javascript-is-this-possible/#findComment-664402 Share on other sites More sharing options...
CBR Posted October 13, 2008 Author Share Posted October 13, 2008 when I do that, it does not load the javascript? Here is my entire code. <?php $myid = 85; ?> <script type="text/javascript" src="js/prototype/prototype.js"></script> <script type="text/javascript" src="js/bramus/jsProgressBarHandler.js"></script> <div class="percentImage1" id="element6">[ Loading Progress Bar ]</div> <script type="text/javascript"> Event.observe(window, 'load', function() { manualPB2 = new JS_BRAMUS.jsProgressBar( $('element6'), <?php echo $myid; ?>, { barImage : Array( 'images/bramus/percentImage_back4.png', 'images/bramus/percentImage_back3.png', 'images/bramus/percentImage_back2.png', 'images/bramus/percentImage_back1.png' ) } ); }, false); </script> Link to comment https://forums.phpfreaks.com/topic/128272-inserting-an-array-in-javascript-is-this-possible/#findComment-664404 Share on other sites More sharing options...
CroNiX Posted October 13, 2008 Share Posted October 13, 2008 After you run it, look at the source code via your browser (view source)...what does the code look like in there? Link to comment https://forums.phpfreaks.com/topic/128272-inserting-an-array-in-javascript-is-this-possible/#findComment-664413 Share on other sites More sharing options...
CBR Posted October 13, 2008 Author Share Posted October 13, 2008 I got it working! It would help if I had a .php extension now wouldnt uit? Thanks for all of your help! Link to comment https://forums.phpfreaks.com/topic/128272-inserting-an-array-in-javascript-is-this-possible/#findComment-664439 Share on other sites More sharing options...
DarkWater Posted October 13, 2008 Share Posted October 13, 2008 I got it working! It would help if I had a .php extension now wouldnt uit? Thanks for all of your help! Yeah, that could help. xD Link to comment https://forums.phpfreaks.com/topic/128272-inserting-an-array-in-javascript-is-this-possible/#findComment-664441 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.