Jump to content

Inserting an array in javascript? Is this possible?


CBR

Recommended Posts


<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?

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.

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

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>

<?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>

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>


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.