timeshifter
07-23-2008, 10:09 PM
So I have myself an interesting problem that I've been bashing at for about 3 hours solid now and haven't been able to figure out. I have a table that is being generated in an insanely dynamic way. It injects the DOM HTML directly into the page with very careful code to display what it needs and how it needs it. This isn't the issue; that works perfectly. The issue is this: I have one section of check boxes (right now 14 per row) that are grouped together, and one check box at the end of that group that should mark all of the others. As I said, there's no ID or name value currently because of how it's being injected, but adding said fields wouldn't be very difficult. What I'm currently trying is something like this:
Each of the check boxes to be marked has an 'onclick' event. What my goal is is to get an array using document.getElementsByTagName('input'), loop through that and identify the check boxes, and if it's a check box, analyze its' 'onclick' attribute to see if its' parameters match the criteria for one that needs to be checked. With this method, it should (theoretically) be capable of only marking the check boxes that need to be checked in the current table row. However, I keep getting the error "array[index] is not defined" when trying to immediately access an item, but when I do a check for null, nothing gets looked at, even though the array's length is 209. Any thoughts as to what might be breaking this thing?
function CheckAllStepsForVehicle(vehID, cbStatus)
{
var cbs = document.getElementsByTagName('input');
var index=0;
for(index = 0; index < cbs.length; index++)
{
if(cbs.item[index] != null) //with this conditional, loop never gets past this point
{
// var m = cbs.item[index].getAttribute("type");
// alert(m);
if(cbs.item[index].getAttribute("type") == 'checkbox')//without previous conditional, this line returns error "cbs.item[index] is not defined"
{
if(cbs.item[index].getAttribute("onclick").search('UpdateStep(this, \'' + vehID) > -1)
{
cbs.item[index].checked = cbStatus;
}
}
}
}
}
Each of the check boxes to be marked has an 'onclick' event. What my goal is is to get an array using document.getElementsByTagName('input'), loop through that and identify the check boxes, and if it's a check box, analyze its' 'onclick' attribute to see if its' parameters match the criteria for one that needs to be checked. With this method, it should (theoretically) be capable of only marking the check boxes that need to be checked in the current table row. However, I keep getting the error "array[index] is not defined" when trying to immediately access an item, but when I do a check for null, nothing gets looked at, even though the array's length is 209. Any thoughts as to what might be breaking this thing?
function CheckAllStepsForVehicle(vehID, cbStatus)
{
var cbs = document.getElementsByTagName('input');
var index=0;
for(index = 0; index < cbs.length; index++)
{
if(cbs.item[index] != null) //with this conditional, loop never gets past this point
{
// var m = cbs.item[index].getAttribute("type");
// alert(m);
if(cbs.item[index].getAttribute("type") == 'checkbox')//without previous conditional, this line returns error "cbs.item[index] is not defined"
{
if(cbs.item[index].getAttribute("onclick").search('UpdateStep(this, \'' + vehID) > -1)
{
cbs.item[index].checked = cbStatus;
}
}
}
}
}