1,105,263 Community Members

How to increment php array variable inside javascript...

Member Avatar
Newbie Poster
10 posts since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]

Hi everyone

echo '<script language="javascript">
var dA = new Array();
var x = 0;


	dA[x++]="'.$date[$i]." ".$message[$i].'";


here i want to increment $i above code is not working, Please help...Thanks in Advance...

Member Avatar
Posting Whiz in Training
219 posts since Dec 2009
Reputation Points: 11 [?]
Q&As Helped to Solve: 45 [?]
Skill Endorsements: 0 [?]

You can't execute a client side(javascript) for loop on the server side(php). You can print javascript out incrementally that would be an array of size 2 using a for loop on your server side. For instance:

$i = 0;
echo '<script type=text/javascript>';
echo 'var dA = new Array();';
for ($i = 0; $i < 2; $i++)
    echo 'dA['.$i.'] = "'.$date[$i].$message[$i].'";';
echo '</script>';
This article has been dead for over three months: Start a new discussion instead
Start New Discussion
Tags Related to this Article