Hi, I need to create a function in javascript to check or uncheck all
checkboxes in a form. From what I understand, I can do this either by
specifying the name of the check box fields such as:
function checkAll(list)
{
var o = document.getElementById(list);
var c = o.checked;
var f = document.forms.f;
var a = f.item(list);
for (var i = 0; i < a.length; i++)
a[i].checked = c;
}
or I can do this by looping through all of the fields in the form and
determining whether they are check boxes such as:
function selectAll(){
var frm = document.forms.f;
for (var i = 0; i < frm.length; i++)
if (frm.elements[i].type == 'checkbox')
frm.elements[i].checked = true;
}
My problem is that the Java code that I am stuck using generates a
unique name for each check box field. It generates the name of the
field in the format 'wire[X].wireAS' where [X] is a number that
increments sequentially based upon the number of fields in the form.
I can't use the second method, looping through all elements in the form
because it takes too long. A test page has 150 check boxes on it and
for each check box there are 8-9 hidden fields. Using IE 6 it takes
about 7 seconds to loop through each field and determine if it is a
check box. (Firefox takes <1 second).
Anyone have any ideas how I can solve this problem?
Thanks in advance.