Friday, May 20, 2011

How to "hide" or make "visible" in javascript when i "check or uncheck" a checkbox

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

<!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">
<script language="javascript" type="text/javascript">
    function forRentClicked() {

        if (document.getElementById('<%=CheckBox1.ClientID%>').checked == true) {

            div1.style.display = 'block';

        }
        else {
           div1.style.display = 'none';
        }
    }  
    </script> 
</head>
<body>
    <form id="form1" runat="server">
    <div> 
    <asp:CheckBox ID="CheckBox1" runat="server" onClick="forRentClicked()" /> 
</div> 
<div id="div1"> 
    <asp:Label ID="Label1" runat="server" Text="Rental rate per week:"></asp:Label> 
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
</div> 
    </form>
</body>
</html>

 

Output:

visible1

0 comments:

Post a Comment