Hello,
I hope I am writing this in the correct thread.
I have pasted relevant code below.
/* convert PHP array ($levels) to Javascript array ($param) */
for($x = 0; $x < count($levels); $x++)
{
$array .= "[" . $levels[$x][0] . ", ". $levels[$x][1] . "]" ;
if($x+1 < count($levels))
$array .= ", ";
}
$param = "new Array( " . $array . ")";
/* end convert PHP array to Javascript array */
echo '<form name="SubjectForm">';
echo 'Subject <br><select name = "subject" onChange="addOptions('. $param . ') ">';
echo '</form>;'
The output of the multi-dimensional array conversion becomes something like this:
new Array( [Math, Algebra I], [Math, Algebra II], [Math, Arithmetic], [Math, Calculus], [Math, Pre-Algebra], [Math , Pre-Calculus], [Math, Statistics], [Math, Trigonometry], [Science, Biology], [Science, Chemistry], [Science, Earth Science], [Science, Physics])
I created a literal declaration of an array and I want to pass it to the addOptions function which is called with an onChange event handler. But when I pass this $param variable, the addOptions function doesn’t work.
However if I manually create a parameter that is an array similar to:
echo ‘Subject <br><select name = “subject” onChange="addOptions( new Array( [1, 2], [3, 4]) ">’;
Then the addOptions function works. So I guess my question is, what am I doing wrong with my conversion of the PHP array to the JS array that is making the addOptions not work?
Thank you very much ahead of time for any help. Take care.