• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to assign javascript variable in a php variable inside javascript function

#1
[eluser]Shiju S S[/eluser]
I have a script with code
Code:
var fcontent=new Array();
var count="<?php echo $ctr;?>";
  
begintag='<div style="font: normal 14px Arial; padding: 5px; text-align:center; ">';
for (j=0; j<count; j++)
{
fcontent[j]="&lt;?php echo $c_purpose[$i];?&gt;";
"&lt;?php echo $i++;?&gt;";
}
closetag='&lt;/div&gt;';

$c_purpose is a php array. I want the array contents to be stored in the javascript array fcontent. $i is not incrementing. What is the solution.

#2
[eluser]InsiteFX[/eluser]
Try this:
Code:
fcontent[j]="&lt;?php echo $c_purpose[$i]; ?&gt;";
"&lt;?php $i++; ?&gt;";
"&lt;?php echo $i; ?&gt;";

#3
[eluser]Shiju S S[/eluser]
It is not working. I tried
Code:
fcontent[j]="&lt;?php echo $c_purpose[$i]; ?&gt;";
"&lt;?php $i++; ?&gt;";
"&lt;?php echo $i; ?&gt;";
var x="&lt;?php echo $i; ?&gt;";
alert(x);
The value is just 1.

#4
[eluser]Shiju S S[/eluser]
I got it with the following jsscript code
Code:
var count="&lt;?php echo $ctr;?&gt;";
   var a=new Array;
   &lt;?php
    for($i=0;$i<count($c_purpose); $i++)
    {
     echo "a[$i]='".$c_purpose[$i]."';\n";
    }
    ?&gt;
where $ctr and $c_purpose are php variables


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.