SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    May 2006
    Posts
    457
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    hide textbox on click of checkbox

    Hello all,
    cam omeone help me out with this code:
    Im looking to hide/show a textbox. When one checkbox is checked the textbox will be displayed, when the other checkbox is checked the textbox will be hidden. The name of the textbox is Other

    Code:
    <%@ Page Language="C#" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
    
        protected void Page_Load(object sender, EventArgs e)
        {
            DiscretionaryCheckbox.Attributes.Add("onclick", "Hide()");
            OtherCheckbox.Attributes.Add("onclick", "Show()");
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <script>
        function Hide() {
    
        }
        function Show() {
    
        }
    </script>
    <body>
        <form id="form1" runat="server">
        <div>
            <table style="width: 616px; height: 106px">
                <tr>
                    <td style="font-size: 9pt; width: 269px; font-family: Arial">
                        <asp:RadioButton ID="DiscretionaryCheckbox" runat="server" AutoPostBack="True" CssClass="Checkbox"
                            GroupName="1" OnCheckedChanged="DiscretionaryCheckbox_CheckedChanged" TabIndex="9"
                            Text="Discretionary" />
                        <asp:RadioButton ID="OtherCheckbox" runat="server" AutoPostBack="True" CssClass="Checkbox"
                            GroupName="1" OnCheckedChanged="OtherCheckbox_CheckedChanged" TabIndex="10" Text="Other" /></td>
                </tr>
                <tr>
                    <td style="font-size: 9pt; width: 269px; font-family: Arial">
                        <asp:TextBox ID="Other" runat="server" CssClass="Textbox" TabIndex="11"></asp:TextBox></td>
                </tr>
            </table>
        
        </div>
        </form>
    </body>
    </html>

  2. #2
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're going to use server side scripting for that?

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would prefer to use client side script due to the fact that if I use server side script, I will need to do a post back.

    Is there a way of hiding a textbox in javascipt?

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why reload the page and then hide the element? Either just reload it and hide, or just hide it without reloading.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •