Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

What is the checkbox array in the DOM?

I have a form with a couple of listboxes and a lot of checkboxes.  I am looking to make all of these checkboxes unchecked.

i.e.
for (var i=0; i<document.form.checkbox.length; i++)
  {
  document.form.checkbox[i].checked = false;
  }

However, whenever I run this, I get an error that says that document.form.checkbox.length is null or not an object.

The only thing I can think of is that checkbox is not the array in the DOM that I am looking for.

What is the correct syntax for this?

BTW  The checkboxes are not the same name, nor can they be the same name.
0
light777
Asked:
light777
1 Solution
 
justinbilligCommented:
try this

for( intIndex = 0; intIndex < document.formname.length; intIndex++ )

{

   if( document.formname[ intIndex ].type  == "checkbox" )
   {
      document.formname[ intIndex ].checked = false;
   }
}


or


for( intIndex = 0; intIndex < document.all.length; intIndex++ )

{

     if( document.all( intIndex ).type == "checkbox" )
     {
          document.all( intIndex )checked = false;
      }
}
0
 
MrClean21Commented:
Here's a technic to uncheck all checkboxes.

for (var c = 0; c < document.form.elements.length; c++)
   if (document.form.elements[c].type == 'checkbox')
      document.form.elements[c].checked = false;

MrClean
0
 
light777Author Commented:
Thanks, that works perfectly
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now