Forum Moderators: open

Message Too Old, No Replies

check and Uncheck all the options

         

phparion

4:27 am on Feb 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi

i have a page where the user can select multiple attributes for products, there is a checkbox in front of every attribute from where he can select multiple checkboxes. i want to give an option to user like

- (checkbox) Check All Options
- (checkbox) UnCheck All Options

Please help me in this.

thanks in advance

JollyK

4:39 am on Feb 22, 2006 (gmt 0)

10+ Year Member



Assuming that the checkboxes are named: box-1, box-2, box-3, etc, then this:

function check_all_boxes (booboo) {

for(var i=1;i<0 + 1;i++){
var blockindex = "box-" + i;
booboo.form[blockindex].checked = true;
}
return false;
}

should check them all. TO uncheck them all, make "true" be "false."

Then in your form, you have something like

<input type=button onclick="check_all_boxes(this);" value="check all">

At least, that's how I've always done it. I'm sure there must be a better way, but that seems to work.

JK