I want to enable text box when first radio button is checked & if second then i want to disable textbox here is my code that is not working please help..
<label class="radio-inline">
<input type="radio" value="Y" name="IsLive" class="grey">
YES
</label>
<label class="radio-inline">
<input type="radio" value="N" name="IsLive" class="grey">
NO
</label>
<label class="col-sm-2 control-label">
Live Date
</label>
<div class="col-sm-3">
<input type="text" id="LiveDate" name="LiveDate" class="form-control date-picker">
</div>
$('input:radio[name="IsLive"]').change(function () {
if ($(this).is(':checked') && $(this).val() == 'Y') {
// append goes here
$("#LiveDate").show();
} else {
$("#LiveDate").prop("disabled", true);
}
});
You can achieve this by just setting the disabled
property based on whether or not the value of the chosen radio is Y
. Try this:
$('input:radio[name="IsLive"]').change(function() {
$("#LiveDate").prop("disabled", this.value != 'Y');
});
Working example
Note that I removed the :checked
condition because it's redundant for a radio button, as to raise a new change
event the element must be checked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With