chazz
02-11-2008, 10:15 PM
hello, I am new to the forum and generally new to the javascript world. I seem to be having a problem hooking events to checkboxes. As I add checkboxes and attach events to them the all get lost except the last one I added.
var vals = document.createElement("input");
vals.setAttribute("type", "checkbox");
vals.onclick = function(){alert("show click");};
p.addControl(vals, "Show Values.");
var checkBox = document.createElement("input");
checkBox.setAttribute("type", "checkbox");
checkBox.setAttribute("checked", "true");
checkBox.onclick = function(){alert("update clicked");};
p.addControl(checkBox, "Auto Update.");
var box = document.createElement("input");
box.setAttribute("type", "checkbox");
box.setAttribute("checked", "true");
box.onclick = function(){alert("another clicked");};
p.addControl(box, "another.");
addControl = function(element, txt)
{
var controls = this.element.getElementsByTagName("controls")[0];
controls.innerHTML += txt;
controls.appendChild(element);
}
So when clicking the checkboxes an alert dialog should show if you click any of the checkboxes, but in this case only the last checkbox added shows the alert. What am i doing wrong here?
thanks
-ChazZ
var vals = document.createElement("input");
vals.setAttribute("type", "checkbox");
vals.onclick = function(){alert("show click");};
p.addControl(vals, "Show Values.");
var checkBox = document.createElement("input");
checkBox.setAttribute("type", "checkbox");
checkBox.setAttribute("checked", "true");
checkBox.onclick = function(){alert("update clicked");};
p.addControl(checkBox, "Auto Update.");
var box = document.createElement("input");
box.setAttribute("type", "checkbox");
box.setAttribute("checked", "true");
box.onclick = function(){alert("another clicked");};
p.addControl(box, "another.");
addControl = function(element, txt)
{
var controls = this.element.getElementsByTagName("controls")[0];
controls.innerHTML += txt;
controls.appendChild(element);
}
So when clicking the checkboxes an alert dialog should show if you click any of the checkboxes, but in this case only the last checkbox added shows the alert. What am i doing wrong here?
thanks
-ChazZ