Zero a checkbox object from a script
Posted on 2002-07-18
I have a number of lines which uses some checkboxes in html like this:
<input type='checkbox' name='XXXcb' value='1' onclick='unCheckOthers(this);'>
<input type='checkbox' name='XXXcb' value='2' onclick='unCheckOthers(this);'>"
<input type='checkbox' name='XXXcb' value='3' onclick='unCheckOthers(this);'>"
and the unCheckOthers JS function looks like this:
var objGroup = obj.form[obj.name];
var boxEmpty = true;
for (var i = 0; i < objGroup.length; i++)
if (objGroup[i] != obj)
objGroup[i].checked = false;
if (objGroup[i].checked == true)
boxEmpty = false;
if (boxEmpty == true)
// checkbox has been unclicked, set value to zero
obj.value = 0;
The first part of the js code unchecks the other two checkboxes when one is clicked (making it somewhat in a radiobutton fashion, but with the option to zero all checkboxes), and that works fine. The old checking is removed when I click a new one.
I MUST do this dynamically, as the X's in the name 'XXXcb' name can be quite a large number of different values.
Any help would be appreciated.