Dynamic function for select all check box

Dynamic function for select all check box

function checkAll(frm1,formid,checkbox_name) {
var aa = document.getElementById(formid);
for (var i =0; i < aa.elements.length; i++)
{
if(aa.elements[i].type == “checkbox” && aa.elements[i].name == checkbox_name)
aa.elements[i].checked = frm1.checked;
}
}

<form id=”check” name=”form1″>
<input type=”checkbox”  name=”check_all” id=”check_all” onclick=”checkAll(document.form1.check_all,’check’,’test[]’)”>
//<input type=”checkbox” onclick=”toggleChecked(this.checked)”>
//For jquery function

All
<input type=”checkbox” name=”test[]” />
1
<input type=”checkbox” name=”test[]” />
2
<input type=”checkbox” name=”test[]” />3
</form>

In Jquery

function toggleChecked(status) {
$(“#checkboxes input”).each( function() {
$(this).attr(“checked”,status);
})
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*
Website