Saturday, November 13, 2010

How to select all and unselect all checkbox using Jquery

<form>
    <div id="checkboxId">\n
    <input type="checkbox" name="chkBox[]" id="chkBox[]">
    <input type="checkbox" name="chkBox[]" id="chkBox[]">
    <input type="checkbox" name="chkBox[]" id="chkBox[]">
    </div>\n
    <input type="checkbox" name="selectAll" id="selectAll" 
onclick="selectAllCheckbox('checkboxId', this);">
</form>
</div>
<script language="javascript" src="jquery.js" 
type="text/javascript">
</script>
<script language="javascript">
function selectAllCheckbox(divname, obj)
{  

 if (obj.checked)
 {\n
  $"#" + divname + " input[type='checkbox']").attr('checked', true);
 }
else
 {
 $("#" + divname + " input[type='checkbox']").attr('checked', false);
}
}
</script>

No comments:

Post a Comment