Archive

Archive for July, 2014

Hide and Show Table based on selection of any one CheckBox

July 17, 2014 Leave a comment

Hi all,

try this example to Hide and show table based on selection of any one checkbox using Javascript


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx.cs" Inherits="Default6" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/start/jquery-ui.css"
rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
//Attach event handlers for all checkboxes
$('#<%=check1.ClientID%>,#<%=check2.ClientID%>,#<%=check3.ClientID%>').on("click", function () {
//Check atlest one checkbox is checked
if ($("input[type=checkbox]:checked").length > 0) {
//Show the table
$('#<%=tblone.ClientID %>').show();
}
else {
//hide the table
$('#<%=tblone.ClientID %>').hide();
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBox ID="check1" runat="server" Text="Check 1" />
<asp:CheckBox ID="check2" runat="server" Text="Check 2" />
<asp:CheckBox ID="check3" runat="server" Text="Check 3" />
<table id="tblone" runat="server" style="display: none">
<tr>
<td>
Testing
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

Hope this helps

Good Luck.

Categories: ASP.Net, Javascript