Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What is the checkbox array in the DOM?

Posted on 2004-08-16
3
Medium Priority
?
246 Views
Last Modified: 2011-10-03
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
Comment
Question by:light777
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Expert Comment

by:justinbillig
ID: 11814680
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
 
LVL 4

Accepted Solution

by:
MrClean21 earned 500 total points
ID: 11814687
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
 
LVL 1

Author Comment

by:light777
ID: 11814739
Thanks, that works perfectly
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question