[Javascript] Select all when a chekcbox is checked
Peter Brunone
peter at brunone.com
Sat Apr 28 15:00:01 CDT 2001
Reuben,
You would need an onClick() event handler in the checkbox that calls a
JavaScript function, like this:
<INPUT TYPE = "CHECKBOX" NAME="all" onClick="selectAll()">
Then in the function you would iterate through the values in the SELECT
element and change the selected property to true, like this:
function selectAll() {
var i = 0;
while(i<document.formName.selectName.options.length) {
document.formName.selectName.options[i].selected = true;
i+=1;
}
}
I haven't tested this; it may be that you need to stop at length-1, but you
can tweak it as necessary.
Cheers,
Peter
|-----Original Message-----
|From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
|Behalf Of Reuben D Budiardja
|Sent: Saturday, April 28, 2001 2:34 PM
|To: javascript at LaTech.edu
|Subject: [Javascript] Select all when a chekcbox is checked
|
|
|
|Hello,
|Suppose I have a multiple selection form, something like this:
|
|<SELECT NAME="assignments" MULTIPLE SIZE="9">
| <OPTION NAME=bla>Bla
| <OPTION NAME=foo>foo
|etc..
|</SELECT>
|
|<INPUT TYPE = "CHECKBOX" NAME="all> Select All
|
|What I want to do is when the checkbox is checked, all the selection is
|selected. Could someone help me with this?
|
|Thanks A lot.
|Reuben D. Budiardja
|
|
|
|
|Reuben D. Budiardja
|Web Database Application Programmer / Analyst
|Devcorps, ITS
|Goshen College, IN 46526
|
|
|_______________________________________________
|Javascript mailing list
|Javascript at LaTech.edu
|http://www.LaTech.edu/mailman/listinfo/javascript
|
More information about the Javascript
mailing list