Jump to content

Pass PHP variable (array value) to javasript variable


vikaspa

Recommended Posts

Dear All

 

find below a code to populate / display a table

 

The values in array are taken from a stream file or test file made using note pad and hence are changing

 

In tthis i had specified subject as subject="abcd"

where asd I want this subject as array valu i.e.  $array[$i];

 

How can I do this ...Please help

 

 

<table width="100%" border="0" cellspacing="0" cellpadding="0">

              <tr>

                <td height="19" colspan="3" valign="top"> </td>

              </tr>

              <?php

  for ($i=0; $i<=$la-1; $i++)

  {

  ?>

              <tr>

                <td width="8%" align="center"> </td>

                <td width="19%" height="25" align="center" valign="top"><img src="bluearrow.jpg" width="15" height="11" vspace="2"></td>

                <td width="73%" height="25" valign="top"><span class="text12b"> <a href="mailto:[email protected]?subject="abcd"><?php echo $array[$i]; ?></a></span></td>

              </tr>

              <?php

              }

 

 

?>

            </table>

to pass a php variable to a javascript variable, use this template:

<script>
    jsvariable = "<?php echo addslashes($phpvariable); ?>";
</script>

notice the quotes in that statement.  they are necessary if passing a string variable.  if passing a number leave off the quotes and the addslashes().

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.