Enable / Disable ASP.NET TextBox control using jquery
The following code snippet will give you an idea for enabling or disabling an asp.net control using jquery,
Here, based on the option (true or false), I am enabling / disabling a textbox, setting its background color to lightgrey and clearing the text.
<head runat=”server”>
<script src=”Scripts/jquery-1.8.2.min.js” type=”text/javascript”></script>
<script type=”text/javascript” language=”javascript”>
$(document).ready(function () {
var optionChkBox = $(“#chkOption”)
optionChkBox.change(function () {
var status = optionChkBox.is(‘:checked’)
var nameTxtBox = $(“#txtBoxName”)
if (status) {
nameTxtBox.attr(‘disabled’, false)
nameTxtBox.css(“background-color”, “white”)
}
else {
nameTxtBox.val(”)
nameTxtBox.attr(‘disabled’, true)
nameTxtBox.css(“background-color”, “lightgray”)
}
})
});
</script>