How to clear a textbox based on a checkbox using Javascript

Posted by LoftyWofty on Stack Overflow See other posts from Stack Overflow or by LoftyWofty
Published on 2013-11-13T02:54:34Z Indexed on 2013/11/13 3:53 UTC
Read the original article Hit count: 115

Filed under:
|
|
|
|

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

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery