I am writing a php script which generates html with a javascript onkeyup event, as such:
// generate the function text
$fn_text = "checkContentQuizAnswer(\"#".$var_name."\",\"".$equation_solutions_array[0][0]."\",\"{'incorrect_values':[";
for($r=1;$r<count($equation_solutions_array);$r++) {
// THIS ISNT WORKING CORRECTLY, NEED A BETTER WAY TO PASS INCORRECT INFO
$fn_text .= "{'equation':'".$equation_solutions_array[$r][0]."','message':'".$equation_solutions_array[$r][1]."'}";
if(($r+1)<count($equation_solutions_array)) {
$fn_text .= ",";
}
}
$fn_text .= "]}\")";
However this isnt working... the code it generates looks something like this:
onkeyup="checkContentQuizAnswer("#theonlyvariable","27.62*5","{'incorrect_values':[{'equation':'27.62+5','message':'you added 5'},{'equation':'27.62-5','message':'you subtracted 5'}]}")"
however, it hasn't been working... the errors have included complaints about missing }'s, MathJax (an eval() style library) is undefined.
Im sure that it is how I am parsing the onkeyup part of the tag but i cant get the combination/syntax correct.
Can anybody see a glaring problem? :S
Thanks Alex