Link to home
Start Free TrialLog in
Avatar of Jeiko
Jeiko

asked on

Copy php array to a javascript array

Hope someone can help with this.

I have an array that I got from a database and want to load it into javascript array.  It seems I have tried everything I can think of and have tried to find another question that fits my situation.

Here is a small section of the code:

<?php
echo "<script type=\"text/javascript\" language=\"Javascript\">";
?>

jimageNum[0]=<?php echo $imageNum[0]; ?>;

<?php
echo "</script>";
?>

The 4th line is where I am trying to set the first element of the javascript array to the first element of the php array.  I will be replacing this with a for loop.  Currently this is in the head, but I have tried it in the body.

I'll be thankful for any help on this.

John
ASKER CERTIFIED SOLUTION
Avatar of StormyWaters
StormyWaters
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of List244
List244

jimageNum[0]=<?php echo $imageNum[0]; ?>;

Shouldn't that be:

jimageNum[0]=<?php $imageNum[0]; ?>;
Avatar of Jeiko

ASKER

StormyWaters, you taught me something very valuable.  I looked at the source code and the problem was obvious.  I was missing the quotes.  It should be:

jimageNum[0]="<?php echo $imageNum[0]; ?>";

Thanks a bunch!  Here's a few extra points.
<no-points>

Jeiko are you all set with this question?  It sounds like you are.   I think you forgot to accept the answer

</no-points>