Home > ASP.Net, Javascript > Hide and Show Table based on selection of any one CheckBox

Hide and Show Table based on selection of any one CheckBox


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.

Advertisements
Categories: ASP.Net, Javascript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: