tags:

views:

519

answers:

4

Hi,

I am html page with 5 checkboxes

My requirement is to have one morecheckboxes "Select All" which is used to select all 5 checkboxes.

Thanks in advance

Closed as exact duplicate of this question.

+1  A: 

If you're looking for javascript that will check your 5 checkboxes when the 6th is clicked, something like this should work:

function CheckAll(value){
    document.getElementByID("CheckBox1").checked = value;
    document.getElementByID("CheckBox2").checked = value;
    document.getElementByID("CheckBox3").checked = value;
    document.getElementByID("CheckBox4").checked = value;
    document.getElementByID("CheckBox5").checked = value;
}

<input type="checkbox" id="CheckBox6" onclick="CheckAll(this.checked)"><label>Check All</label>
Pwninstein
A: 

In "pure" HTML, you can't, though you can modify your server-side code to correctly interpret that checkbox as meaning "act as though all the others were checked".

It's fairly easy using Javascript. Create a method that is fired when the "select all" checkbox is checked, and then find the other checkboxes by ID and mark them as checked. It's unclear what you should do if the "select all" checkbox is unchecked though, so perhaps it should just be a link.

Graeme Perrow
A: 

You can't do this in just HTML, but should be fairly simple with javascript.

Personally I would use jQuery like this: http://abeautifulsite.net/notebook/50

DanSingerman
A: 

This is a job for jQuery. Spend some time today and learn about it if you can. It's awesome for just this sort of task.

Dave Markle