Main Topics
Browse All TopicsHi all!
I am new to JavaScript and I have a little question. I have several checkboxes in my page. I would like by clicking on the SelectAll one, all the other to be checked.
Thank you!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thanks all!
I increased the number of points since I got a really good positive feedback. The problem which arises now is the following: The "master" select all checkbox relates to 3 "slave" ones in the first place.
But later on in the same form are 2 more checkboxes which are related to enable/disable a textfield. If I implement the above code all the checkboxes will be checked when the "master" one is selected. How can I fix this?
Thanks again!
Hi,
Here's a little script I wrote a while back that enables you to either select all or "all but" (inverse)
http://www.grassblade.net/
Alternatively do this if your checkboxes have different names:
var checkSet = "chk1,bla234,x25".split(",
function checkAll(chk,nameArray) {
var theForm = chk.form;
var chkd = chk.checked;
for (var i=0;i<nameArray.length;i++
var elem = theForm.elements[nameArray
elem.checked=chkd;
}
}
and call it
<input type="checkbox" onClick="checkAll(this,che
<input type="checkbox" name="chk1">chk1<br>
<input type="checkbox" name="bla234">bla234<br>
.
.
You can use ID too:
var checkSet = "chk1,bla234,x25".split(",
function checkAll(chk,nameArray) {
var theForm = chk.form;
var chkd = chk.checked;
for (var i=0;i<nameArray.length;i++
var elem = document.getElementById(na
elem.checked=chkd;
}
}
and call it
<input type="checkbox" onClick="checkAll(this,che
<input type="checkbox" id="chk1" name="checkbox1>chk1<br>
<input type="checkbox" id="bla234" name="checkbox2">bla234<br
.
.
styleId:
Identifier to be assigned to this HTML element (renders an "id" attribute). [RT Expr]
property:
Name of the request parameter that will be included with this submission, set to the specified value. WARNING - If you set this attribute to a value other than the default, this will NOT be recognized as the cancel key by the Struts controller servlet or the Action.isCancelled() method. You will need to do your own cancel detection. [RT Expr]
sounds like you should use the ID
Business Accounts
Answer for Membership
by: pratima_mcsPosted on 2008-01-03 at 04:20:33ID: 20572182
http://www.dustindiaz.com/ check-one- check-all- javascript /