Click to See Complete Forum and Search --> : how to check the state of a checkbox


lcscne
10-06-2003, 03:18 PM
My bad, disregard this message, my problem was elsewhere.

for (i=0; i<document.frmStudentList.elements.length; i++)
{
if(document.frmStudentList.elements[i].type == "checkbox")
{
if(document.frmStudentList.elements[i].checked)
.....

I'm trying to check the state of checkbox so I can perform action. However I'm getting "Invalid Argument" on the second if statement. Any suggestions on how to check the state of a checkbox while in an array like this?

Khalid Ali
10-06-2003, 06:54 PM
that could be due to the fact that the element you are trying to access "checked" property of, does not realy have that property,which means you are trying to access "checked" property for buttons other then radio and checkbox buttons

pyro
10-06-2003, 07:59 PM
Take a look at the code (http://forums.webdeveloper.com/showthread.php?s=&threadid=18751#post98873) I gave you. I needed to do that in that little snippet...

Hint: it's this part (document.myform.elements[i].type == "checkbox") which can be evaluated as such:

if (document.myform.elements[i].type == "checkbox") {
//do something -- the element is a checkbox
}
else {
//do something else -- the element is not a checkbox
}