Jump to content

Trouble with setting onclick


toxicious
 Share

Recommended Posts

This piece of code is driving me nuts:

function loadBtn(){var theBtn = document.getElementById("gaddonsBtn");  //Add the checkbox	    if (element != null)	    {		    element.innerHTML += '<br /><input type="checkbox" id="autoPick" value="autoPick" style="margin-top: 8px;" /> Auto-pick best mirror';	    }	   	    var checkbox = document.getElementById("autoPick");  //Add the save event  if (checkbox != null)	    {		    document.getElementById("autoPick").addEventListener("click", saveAutoPick, false);	    }  theBtn.addEventListener("click", navigate, false);}

The problem is that when I click "theBtn" nothing happens. But if I remove all the checkbox code (all code except the first and last line) the button do work.There is something wrong with that checkbox code. The checkbox gets added, I can view it, and its click event works too. The only thing that doesn't work here is the damn button. It would be great if someone could help me on what's wrong here!

Link to comment
Share on other sites

Have you verified that it is calling the navigate function when you click on the button? Are you checking for Javascript error messages?
Yes, I have an alert on the click event. If I remove the checkboxes code (as I said) that alert goes off.Where should I check for the errors?
Link to comment
Share on other sites

Try getting firebug from here and start debugging from there.

Link to comment
Share on other sites

even without Firebug it still has error console. or just use Chrome/Safari. They both have a full suite of developer tools built in.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...