I have a problem with my javascript code. I am trying to pass a parameter to the checkAnswer function during using the onClick event handler.
I wrote the following lines of code:
Expand|Select|Wrap|Line Numbers
- var option2= document.createElement("input");
- option2.type = "button";
- option2.name = alldetails[3];
- option2.id = "test123";
- option2.value = alloptions[1];
- tr_a.appendChild(td(option2));
- var testx = option2.name;
- // alert(testx);
- option2.onclick = new Function('checkAnswer(' + testx + ')'
- )
Expand|Select|Wrap|Line Numbers
- function checkAnswer(response)
- {
- alert(response);
- }
“Error: Europe is not defined”
Any help would be apprectiated. I basically want the value from the array to be passed to another function upon clicking the button.