Jump to content

Declaring JavaScript variables in a Lopp


james909

Recommended Posts

 
I am trying to declare javascript variables from php array values using a loop.
 
Trying to declare javascript var h1 as php array value from $array[1][h], and h2 as $array[2][h], and h3 as $array[3][h],and so on...
 
Here is my code:
<SCRIPT LANGUAGE="JavaScript">

for (var i=0;i<61;i++)
{
var h[i] = "<?php echo $array[i][h] ?>";
var hl[i] = "<?php echo $array[i][hl] ?>";
var hs[i] = "<?php echo $array[i][hs] ?>";
} 

</script>

 When I <script type="text/javascript"> document.write(h1); </script> it is blank

 

Link to comment
Share on other sites

No. You need to use php.

 

<script>
<?php
for ($i=0; $i < 61; $i++) {
  echo "var h[{$i}] = '{$array[$i]['h']}';";
  echo "var h1[{$i}] = '{$array[$i]['h1']}';";
  echo "var hs[{$i}] = '{$array[$i]['hs']}';";
}
?>
</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.