Select All Checkboxes in a Form with JavaScript

Select All Checkboxes in a Form with JavaScript

By Shawn Olson

Posted on 04.21.04

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.

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:





select/unselect


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>
Copyright © 2004-2008 by Shawn Olson.

Comments

< Ijustwaisted 30minsofmylife > at 2008-05-28 12:59:23 EST Email Me

If the script does work, you need to explain in further detail what is required.


Your own script doesnt work on your own page with only a different server and the source 100% intact, that's no good.

< Shawn Olson > at 2008-05-21 22:31:28 EST Email MeMy Website

I am sorry that the script was temporarily broken. While loading an update to the JavaScript file, it appears that there was corruption with the file. I have reloaded the file... so it should work fine now.

< Patricia Hswe > at 2008-05-21 22:16:14 EST Email Me

Is there an error in the code on this page:

http://www.shawnolson.net/scripts/public_smo_scripts.js

where the code reads:

}iteCheckRound]);

What is "ite"?

Thanks,
Patricia

< Al Smith > at 2008-03-03 22:25:16 EST Email MeMy Website

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?

< jo jo > at 2007-11-08 02:11:13 EST Email MeMy Website

hi, great code
but, how to make some exception ?
tks

< Jerome Uy > at 2007-09-07 05:15:01 EST Email Me

perfecto!! work like a charm!

< Riaan Venter > at 2007-07-09 20:11:35 EST Email Me

Thanks Shawn, just what I needed!

< Nick ConeDog > at 2007-05-17 02:48:41 EST Email MeMy Website

Worked perfectly! Thanks!

< Kelvin Wright > at 2007-02-01 11:26:14 EST Email Me

Thanks for this - just what I needed - something short and sweet

< John Eubanks > at 2007-01-10 11:09:33 EST Email MeMy Website

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.

< roopesh gottipati > at 2006-12-22 07:54:19 EST Email Me

it is damn good

< govind gupta > at 2006-12-03 23:19:15 EST Email Me

no

< Bala Chandar > at 2006-11-28 02:26:08 EST Email Me

Simply Perfection!
All The Best

< Richand > at 2006-08-31 18:57:02 EST Email MeMy Website

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 Email MeMy Website

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:

< carol carol > at 2006-07-25 11:12:57 EST Email Me

how to select/unselect only some checkbox? I want to decid with of them to check nota ll
Shawn Olson Creative Arts
sitemap RGB Color Columbus Photography Free Word Search Maker monty hall game Hangman John Dewey