How to clear a textbox based on a checkbox using Javascript
- by LoftyWofty
I am trying to code in javascript (to avoid validation triggers at the server) to clear a text box if the checkbox associated with it is unchecked.
I have this code ...
<input type="checkbox" id="chkOTHER" onclick="document.getElementById('txtOtherFlag').value='';" />
<asp:TextBox ID="txtOtherFlag" runat="server" AutoPostBack="True" CausesValidation="True" ValidationGroup="ValidationGroup1"></asp:TextBox>
The problem is the Javascript inside the checkbox is not triggering to remove the value in the text box. Even if this worked, it's incorrect as it would blank out the text box every time the checkbox is triggered whether it is checked or not.
I need to resolve this in the client side only.
Thank you