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?

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.