disabling the other checkboxes while seleting one checkbox and enabling all checkboxes while deselecting it.

Nithadeepak
Posted by Nithadeepak under jQuery category on | Points: 40 | Views : 3612
aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="JScript.js"></script> //reference to jquery plugin
<script type="text/javascript" src="JScript2.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="chk1" runat="server">
<asp:ListItem >1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
</asp:CheckBoxList>
</div>
</form>
</body>
</html>

JScript2.js
$(document).ready(function() {

jQuery("#chk1").click(function() {
var isvalid = false;
$("#chk1").find(":checkbox").each(function() {
if ($(this).attr("checked")) {
isvalid = true;
}

});
if (isvalid == false) {
jQuery("#chk1").find(":checkbox").each(function() {
$(this).removeAttr("disabled");

});
}
else

if (isvalid == true)
{
jQuery("#chk1").find(":checkbox").each(function() {

if (jQuery(this).attr("checked")) {

$(this).attr("enabled", "enabled");

}
else {
$(this).attr("disabled", "disabled");

}



});
}


});

});

Comments or Responses

Login to post response