Reputation: 63
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%" />
Upvotes: 1
Views: 513
Reputation: 7135
Should do it
Upvotes: 1
Reputation: 498992
There are several way to get this to work.
id
, use the .ClientId
property of the control. So, if your htmlChkNotify
is server side, you can use var checkbox = $('#<%=htmlChkNotify.ClientId%>');
Upvotes: 1
Reputation: 517
See generated HTML ("view source" in browser)
and check IDs of checkbox and textbox
Upvotes: 0