Select All Checkboxes in a Form with JavaScript

Posted Apr 20, 2004
Last Updated Nov 5, 2011

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>

Comment

No HTML Tags are permitted.

jay

Dec 27, 2012

yeah really awesome..thanks a lot!

sonal

Sep 27, 2012

thanks..Its good

vikas gupta

Mar 17, 2011

Good..nice script its work smoothly..

thank u for sharing.

Noble Silence

Feb 8, 2011

Very good! Thank you for the script.

vicky shrestha

Aug 19, 2010

thank u so much it worked..

Boros Csaba

Apr 7, 2010

If somebody is interested I have a post abouthow to check or uncheck all checkboxes using a button.

Mark Iliff

Dec 11, 2009

Good stuff. Thanks for sharing.

Dusty Roberts

Dec 24, 2008

This article could also assist: http://laymensterm.blogspot.com/2008/12/javascript-select-all-none-checkboxes.html

Matthew Jenne

Nov 10, 2008

Great script. Just one question. How could I get it to work with more than one checkbox group??



Thanks

gus wah

Oct 27, 2008

I'd like a checkbox that, when checked, UNCHECKS the other checkboxes in a single array. Is there a simple mod to your script that would do this?

Ijustwaisted 30minsofmylife

May 28, 2008

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

May 21, 2008

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.

Sujith Kumar

Aug 13, 2008

really wonderful code,thanx a lot and God Bless U

Patricia Hswe

May 21, 2008

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

Mar 3, 2008

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

Nov 7, 2007

hi, great code

but, how to make some exception ?

tks

Jerome Uy

Sep 7, 2007

perfecto!! work like a charm!

Riaan Venter

Jul 9, 2007

Thanks Shawn, just what I needed!

Nick ConeDog

May 16, 2007

Worked perfectly! Thanks!

Kelvin Wright

Feb 1, 2007

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

John Eubanks

Jan 10, 2007

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

Dec 22, 2006

it is damn good

govind gupta

Dec 3, 2006

no

Bala Chandar

Nov 27, 2006

Simply Perfection!

All The Best

Richand

Aug 31, 2006

Thanks a lot for the script! It was exactly what I was looking for and it worked like a charm.

Larry Solheim

Aug 10, 2006

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:

umar rehman

Feb 19, 2009

Hi, its nice and easiy script.



Is there any way to check/uncheck all checkboxes through dynamic check box?

carol carol

Jul 25, 2006

how to select/unselect only some checkbox? I want to decid with of them to check nota ll

Shawn Olson

Jul 25, 2006

I have added just the function you want at checkUncheckSome(). That will handle checking/unchecking just the checkboxes you want.

Comment ignored.

Youcef Kelanemer

May 4, 2004

I download your javascript for checkUnchekAll and modified a little to make work when you put the checkbos for chechUnchekAll at the begining of the list:



function checkUncheckAll(theElement) {

var theForm = theElement.form, z = 0;

while (theForm[z].type == 'checkbox') {

if (theForm[z].name != 'checkall') {

theForm[z].checked = theElement.checked;

}

z++;

}

}



Thank you, though.
Wall Worm plugins and scripts for 3ds Max