Select All Checkboxes in a Form with JavaScript
This simple JavaScript function allows you to quickly select or unselect all the checkboxes in a form.
NOTE: This function was updated on January 4, 2006 to work no matter where you place the event handler checkbox named "checkall". Also... there is a more versatile function called checkUncheckSome() that has more control.
To use this function place the following code inside the head of your HTML:
Using this code and applying an input with the name of "checkall" you can select or unselect all checkboxes.
Example:
Example code below:
<form><input type="checkbox" name="check1"/>
<br/>
<input type="checkbox" name="check2"/>
<br/>
<input type="checkbox" name="check3"/>
<br/>
<input type="checkbox" name="check4"/>
<br/>
<input type="checkbox" name="check5"/>
<br/>
<input type="checkbox" name="checkall" onclick="checkUncheckAll(this);"/>select/unselect</form>
NOTE: This function was updated on January 4, 2006 to work no matter where you place the event handler checkbox named "checkall". Also... there is a more versatile function called checkUncheckSome() that has more control.
function checkUncheckAll(boxController)To use this function place the following code inside the head of your HTML:
<script type="text/javascript" src="http://www.shawnolson.net/scripts/public_smo_scripts.js"></script>
Please include credit when using this script and read this site's Terms & Conditions before using.Using this code and applying an input with the name of "checkall" you can select or unselect all checkboxes.
Example:
Example code below:
<form><input type="checkbox" name="check1"/>
<br/>
<input type="checkbox" name="check2"/>
<br/>
<input type="checkbox" name="check3"/>
<br/>
<input type="checkbox" name="check4"/>
<br/>
<input type="checkbox" name="check5"/>
<br/>
<input type="checkbox" name="checkall" onclick="checkUncheckAll(this);"/>select/unselect</form>
- Search for JavaScript articles similar to "Select All Checkboxes in a Form with JavaScript".
- Search all articles similar to "Select All Checkboxes in a Form with JavaScript".
- List all JavaScript articles by Shawn Olson.
- List JavaScript articles from all authors.
Copyright © 2004-2008 by Shawn Olson.
< Al Smith > at 2008-03-03 22:25:16 EST
I can get this to work perfectly when using firefox but in IE7 for some reason it does nothing - any idea what I could be doing wrong?
< Kelvin Wright > at 2007-02-01 11:26:14 EST
Thanks for this - just what I needed - something short and sweet
< John Eubanks > at 2007-01-10 11:09:33 EST
Awesome script. I was looking for something to use with dynamic checkboxes in coldfusion. Most scripts deal with static text boxes, which don't work very well. Thank you very much, a very nice piece of work.
< Richand > at 2006-08-31 18:57:02 EST
Thanks a lot for the script! It was exactly what I was looking for and it worked like a charm.
< Larry Solheim > at 2006-08-11 01:24:23 EST
No site yet, but am looking to create one for a car club. For an email feature I will read names into an array from a mySQL database, then list them on the website where members can send emails to other members (access is password protected). This seeems to work as written, but it is a lot oc "checking" to select all 36 members. Could your script be made to work w/ these prelisted, variable entries?
--Larry
Home
New Page 1
Contact the Members
Your Name (sender):
Subject:
Select Addressees:
[ Comment on This ]
Comments
< Al Smith > at 2008-03-03 22:25:16 EST 

I can get this to work perfectly when using firefox but in IE7 for some reason it does nothing - any idea what I could be doing wrong?
< Kelvin Wright > at 2007-02-01 11:26:14 EST 
Thanks for this - just what I needed - something short and sweet
< John Eubanks > at 2007-01-10 11:09:33 EST 

Awesome script. I was looking for something to use with dynamic checkboxes in coldfusion. Most scripts deal with static text boxes, which don't work very well. Thank you very much, a very nice piece of work.
< Richand > at 2006-08-31 18:57:02 EST 

Thanks a lot for the script! It was exactly what I was looking for and it worked like a charm.
< Larry Solheim > at 2006-08-11 01:24:23 EST 

No site yet, but am looking to create one for a car club. For an email feature I will read names into an array from a mySQL database, then list them on the website where members can send emails to other members (access is password protected). This seeems to work as written, but it is a lot oc "checking" to select all 36 members. Could your script be made to work w/ these prelisted, variable entries?--Larry
Home
New Page 1
Contact the Members
Your Name (sender):
Subject:
Select Addressees:
More in the Free Useful Javascripts Series
- Strip Character and Whitespace in JavaScript Function
- Altering CSS Class Attributes with JavaScript
- [ Select All Checkboxes in a Form with JavaScript ]
- Using an Object Id with JavaScript
- InnerHTML JavaScript Functions
- Hide Select Menus JavaScript
- Select Some Checkboxes JavaScript Function
- Select Radio Inputs JavaScript
- UseMaps Crash IE When Changed







