taji01
taji01

Reputation: 2615

Hide Table Row with ASP Control Checkbox

In my web page, I have a table with a textbox. I want to hide the table row with the textbox If my ASP checkbox is checked. How can I do that?

This is what I have so far:

<table>
<tr>
    <td>
        <asp:CheckBox id="chkbxUS" runat="server" onchange="validate();" />
    </td>
</tr>
  <tr>
    <td id="ParentCountryInfo">
      <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </td>
  </tr>
</table>

<script type="text/javascript">
    function validate() {
        if (document.getElementById('<%=chkbxUS.ClientID%>').checked) {

            document.getElementById("ParentCountryInfo").style.visibility='visible';

        } else {
            document.getElementById("ParentCountryInfo").style.display='block';
        }
    }

</script>

Upvotes: 0

Views: 955

Answers (1)

kblau
kblau

Reputation: 2107

Can you please try this:

<table>
    <tr>
        <td>
            <asp:CheckBox ID="chkbxUS" runat="server" onchange="validate();" />
        </td>
        <td id="ParentCountryInfo">
            <asp:TextBox ID="TextBox1" runat="server">Disappear me</asp:TextBox>
        </td>
    </tr>
</table>

<script type="text/javascript">
    function validate() {
        if (document.getElementById('<%=chkbxUS.ClientID%>').checked) {
            document.getElementById("ParentCountryInfo").style.visibility = 'hidden';
        } else {
            document.getElementById("ParentCountryInfo").style.visibility = 'visible';
        }
    }
</script>

Upvotes: 1

Related Questions