shreyas35
shreyas35

Reputation: 175

how to hide checkbox and checkbox text using javascript in web forms

I am working on web forms and writing a piece of javascript to hide checkbox and its text but only checkbox is getting hidden Text is still showing the way it was showing earlier.

Here is my view code

<table style="width: 60%">
     <tr>
        <td class="td_150px">
            <asp:CheckBox ID="chkEnddate" runat="server" CssClass="label" Text="End On"
                              onclick="EndSchedule();" TextAlign="Left"/>
         </td>

    </tr>
</table>

So here is my javascript code on click of a radio button i am using below code to hide the checkbox and text but only checkbox is hidden not text.

 var chkEnddate= document.getElementById("ctl00_ContentPlaceHolder1_chkEnddate");
    chkEnddate.style.display = "none";

Can anybody help me to hide checkbox and it's text at the same time using javascript. Thanks in advance.

Upvotes: 1

Views: 831

Answers (1)

Deepu Reghunath
Deepu Reghunath

Reputation: 9673

place the checkbox in the div element and try to hide that div element

<td class="td_150px">
 <div id="chkEnddateBox">
   <asp:CheckBox ID="chkEnddate" runat="server" CssClass="label" Text="End On"
   onclick="EndSchedule();" TextAlign="Left" />
 </div>
</td>

and in the javascript

var chkEnddate= document.getElementById("chkEnddateBox");
chkEnddate.style.display = "none";

Upvotes: 2

Related Questions