Thread: onClick woes
View Single Post
  #1 (permalink)  
Old November 3rd, 2007, 11:22 AM
DennyLoi DennyLoi is offline
Registered User
Join Date: Nov 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default onClick woes

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"; = alldetails[3]; = "test123";
      option2.value = alloptions[1];
      var testx =;
  // alert(testx);
    option2.onclick = new Function('checkAnswer(' + testx + ')'

Where alldetails[3] = “Europe” (I string value in an array).

function checkAnswer(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.

Reply With Quote