PDA

View Full Version : quick trouble shooting question


craigh@mac.com
10-23-2002, 02:48 AM
I was using this function to uncheck a bunch of checkboxes in my form. It works, but I get the errors that are noted. The wierd this is I get 11 of each error, regardless of the number of elements in the array. Any idea what is causing the errors? Especially since it works!?!?!

function uncheck(myArray,field) {
var ele;
for (var i=0; i <= myArray.length; i++) {
ele=field+'[' + myArray[i] + ']'; //Warning: reference to undefined property myArray[i]
document.label.elements[ele].checked=0; //Warning: reference to undefined property document.label.elements[ele]
}
}

glenngv
10-23-2002, 03:16 AM
what are the values of myArray? 0,1,2...?
and also what is the value of field?
can you show where it is called?

craigh@mac.com
10-23-2002, 03:22 AM
Thanks. By changing <= to <, that fixed all the errors. I don't understand your question about the paramenter field though.

glenngv
10-23-2002, 03:38 AM
i modified my post coz i don't know what is this for?

ele=field+'[' + myArray[i] + ']'

that's why I asked what are the values of field and myArray in my edited post.

craigh@mac.com
10-23-2002, 03:46 AM
oh! :-)

ele=field+'[' + myArray[i] + ']';


the checkboxes are named like so:

name='district[1]'

so, in the function, I pass the field ('district') and the array (1,2,3,4,...16). Then the function combines those and modifies each checkbox.

I needed it to be more dynamic so I could use it in several situations.

thanks again for your help.

craig