Toggle checkboxes and uneditable checkboxes
I have a series of checkboxes and a button. When I click the button, I'd like all of the checkboxes to either all turn on, or all turn off (a toggle).
In regular javascript I can do this:
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
}
checkflag = "true";
return "Uncheck All";
} else {
for (i = 0; i < field.length; i++) {
field[i].checked = false;
}
checkflag = "false";
return "Check All";
}
}
<input type=checkbox name=list value="1">Value1<br>
<input type=checkbox name=list value="2">Value2<br>
<input type=checkbox name=list value="3">Value3<br>
<input type=checkbox name=list value="4">Value4<br>
<input type=checkbox name=list value="5">Value5<br>
<br>
<input type=button value="Check All" onClick="this.value=check(this.form.list)">
I'd love a jQuery version of the above.
However, I don't want the user to be able to check or uncheck the checkboxes individually. How do I make those checkboxes uneditable?
I think this is similar to mouseEnabled = false in ActionScript. Is there an equivalent in javascript (preferably jQuery)?