Hi Everyone, 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: 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 + ')' ) Where alldetails[3] = “Europe†(I string value in an array). function checkAnswer(response) { alert(response); } When I click my button, nothing happens. The firefox error console says “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.
This strikes me as troublesome: Where alldetails[3] = “Europe†Code (markup): That's always going to evaluate as true, because you've use the single =, which assigns values to variables, and then returns true if successful. You probably want to use the double ==. Ex: Where alldetails[3] == “Europe†Code (markup): (Note that I've posted my code as code by surrounding it with [CODE] and [/CODE].) Give that a try.