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:nooria@vsnl.com?subject="abcd"><?php echo $array[$i]; ?></a></span></td>

              </tr>

              <?php

              }

 

 

?>

            </table>

Link to comment
Share on other sites

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().

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.