I am using the following code to create a checkbox. I want the checkbox to call another function. The problem is that when the checkbox is created it runs the function and then doesn’t run when clicked.
var cb = document.createElement('input');
cb.type = 'checkbox';
cb.onclick = newfunction();
cb.name = "done";
cb.value = "done";
theCell.appendChild(cb);
How can I fix this so that I can create a checkbox and then have it run functions when clicked. I am using ie8 and Firefox 8. Thank you!
You are executing
newFunctioninstead of assigning it.Remove the
():Alternatively, if you need to pass parameters to
newFunction, wrap it in an anonymous function: