Reputation: 653
I want to enable/disable a text box based on selection of drop down items in a combo box.Earlier text box is in disabled mode, when first option will be selected then text box will be enabled and when second option will be chosen then text box will be disabled again. How can i do it using jquery? Thanks
<select id="combo">
<option value="_">select</option>
<option value="firstoption">firstoption</option>
<option value="secondoption">secondoption</option>
</select>
<input type="text" id="textbox" disabled="true"/>
Upvotes: 2
Views: 4534
Reputation: 100175
$("#combo").change(function() {
if($(this).val() == "secondoption") {
$("#textbox").attr("disabled", "disabled");
}
else {
$("#textbox").removeAttr("disabled");
}
});
Upvotes: 1
Reputation: 174957
$(function() {
$("#combo").change(function() {
if ($(this).val() == "firstoption") {
console.log(true);
$("#textbox").removeAttr("disabled");
}
else {
console.log(false);
$("#textbox").attr("disabled", "disabled");
}
});
});
Upvotes: 2