Tuesday, August 11, 2009

Select All Checkbox on Click of One checkbox in Javascript

==Script in Javascript===
function SelectAllCheckboxes(spanChk)
{
// Added as ASPX uses SPAN for checkbox
var oItem = spanChk.children;
var theBox= (spanChk.type=="checkbox") ?
spanChk : spanChk.children.item[0];
xState=theBox.checked;
elm=theBox.form.elements;

for(i=0;iif(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
{
if(elm[i].checked!=xState)
elm[i].click();
}
}

==Check all checkbox on selection of A Checkbox
input id="Checkbox2" type="checkbox" onclick="javascript:SelectAllCheckboxes(this);" / Check All

No comments: