1

there is a checkbox and a textbox. initially the textbox is set disabled and on checking the checkbox the textbox in enabled. i hv tried this but the problem is that it is not working when runat server is added. or i should change javascript logic for asp.net standard controls. or can suggest me a beeter way to do this.

<script type="text/javascript">
 $(document).ready(function() {
    var checkbox = $('#htmlChkNotify');
    var textfield = $('#htmlTxtNotifyemailaddress');
        checkbox.click(function() {
            if (checkbox.is(':checked')) {
                textfield.removeAttr('disabled');
                textfield.removeClass("email");
            }
            else {
                textfield.attr('disabled', 'disabled');
                textfield.addClass("email");
            }
        });
    });


    </script>

<input type="checkbox"  id="htmlChkNotify"/>
<label for="htmlChkNotify">Notify</label>
<input type="text" id="htmlTxtNotifyemailaddress" disabled="disabled" 
       class="email" style="width:25%" />

3 Answers 3

1

There are several way to get this to work.

  1. Use all server side code.
  2. In your client side (javascript) code, instead of using the server side id, use the .ClientId property of the control. So, if your htmlChkNotify is server side, you can use var checkbox = $('#<%=htmlChkNotify.ClientId%>');
Sign up to request clarification or add additional context in comments.

1 Comment

@kinn - What is not working? I gave two options, and you didn't explain which one didn't work and what exactly didn't work.
1
  1. add the runat attribute to your textbox
  2. Change your 4th line to be var textfield = $('#<%=htmlTxtNotifyemailaddress.ClientID %>');

Should do it

Comments

0

See generated HTML ("view source" in browser)
and check IDs of checkbox and textbox

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.