I have a textbox
and a checkbox
, when the checkbox
is unchecked, I need to disabled the textbox
and when the user selects the checkbox
, I want to re-enable the textbox
.
I tried this:
ASP.NET code:
<div class="checkConfiguration">
<asp:CheckBox runat="server" ID="stopGeneralNumber" Text="General Number" CssClass="cbStopReason" Checked="false" />
<asp:TextBox runat="server" Enabled="false"></asp:TextBox>
</div>
jQuery code
$('.cbStopReason').on('click', function () {
if ($(this).attr('checked')) {
alert("now checked");
$(this).nextAll("input").removeAttr("disabled");
} else {
alert("now un checked");
$(this).nextAll("input").attr("disabled", "disabled");
}
})
The jQuery
code is already in document ready function
, but the problem is that my code works good to disable the textbox
, but it doesn't work to re-enable it, what wrong did I do please?
Update 1: This is the actual HTML that is being generated
<div class="configurationData">
<div class="checkConfiguration">
<span class="cbStopReason"><input id="stopUrgentNumber" type="checkbox" name="stopUrgentNumber"><label for="stopUrgentNumber">Urgent Number</label></span>
<input name="ctl17" type="text" disabled="disabled" class="aspNetDisabled">
</div>
<div class="checkConfiguration">
<span class="cbStopReason"><input id="stopNurseNurse" type="checkbox" name="stopNurseNurse"><label for="stopNurseNurse">Nurse Number</label></span>
<input name="ctl18" type="text" disabled="disabled" class="aspNetDisabled">
</div>
<div class="checkConfiguration">
<span class="cbStopReason"><input id="stopScheduledNumber" type="checkbox" name="stopScheduledNumber"><label for="stopScheduledNumber">Scheduled Number</label></span>
<input name="ctl19" type="text" disabled="disabled" class="aspNetDisabled">
</div>
<div class="checkConfiguration">
<span class="cbStopReason"><input id="stopClockNumber" type="checkbox" name="stopClockNumber"><label for="stopClockNumber">Clock Number</label></span>
<input name="ctl20" type="text" disabled="disabled" class="aspNetDisabled">
</div>
<div class="checkConfiguration">
<span class="cbStopReason"><input id="stopLastCheckNumber" type="checkbox" name="stopLastCheckNumber"><label for="stopLastCheckNumber">Last Check Number</label></span>
<input name="ctl21" type="text" disabled="disabled" class="aspNetDisabled">
</div>
<div class="checkConfiguration">
<span class="cbStopReason"><input id="stopArrivalNumber" type="checkbox" name="stopArrivalNumber"><label for="stopArrivalNumber">Arrival Number</label></span>
<input name="ctl22" type="text" disabled="disabled" class="aspNetDisabled">
</div>
<div class="checkConfiguration">
<span class="cbStopReason"><input id="stopGeneralNumber" type="checkbox" name="stopGeneralNumber"><label for="stopGeneralNumber">General Number</label></span>
<input name="ctl23" type="text" disabled="disabled" class="aspNetDisabled">
</div>
</div>