How can I check all checkboxes in an HTML page with one click?

I am an html page with 5 checkboxes

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

Thank you in advance

Closed as an exact duplicate of this question .

0


source to share


4 answers


If you are looking for javascript that will check your 5 checkboxes when button 6 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>

      

+2


source


In "pure" HTML, you cannot, although you can change your server-side code to correctly interpret this flag to mean "act as if everyone else was checked."



It's pretty simple using Javascript. Create a method that runs when the Select All checkbox is checked and then look for other checkboxes by ID and mark them as checked. It's not clear what you should be doing if the Select All checkbox is not checked, but perhaps it should only be a link.

0


source


You cannot do this in HTML alone, but should be simple enough with javascript.

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

0


source


This is a job for jQuery . Spend some time today and find out if you can. It's just cool for this kind of task.

0


source







All Articles