I have to elements radio button and text field:
<label><input id="GRP010" type="RADIO" value ="900">Radio button</label>
<input id="AF92" maxlength="254" size="15" name="AF92">
I want using jquery to disable text field, but enable it when the radio button is checked and value is equal.
So far I have wrote this:
$(document).ready(function(){
var value2 = $('input:radio[name="GRP010"]').val();
var checked2 = $('input:radio[name="GRP010"]').is(':checked');
if (checked2 == true && value2 == '900') {
$("#AF92").attr("enabled", "enabled");
} else {
$("#AF92").attr("disabled", "disabled");
}
});
However, the text field is disable and not enabled if I select the radio button. How to I achieve this? Thanks
There is no attribute called
enabledit is only disabled, to use it do thisYou also have other problems. First, you are trying to target your input by the wrong attribute
name="GRP010which does not exist, since you have an id just use that. Also, you don’t have an event handler to change the status of the input once the radio button changes, see the live fiddleAlso, it would be better to start the input as disabled.
Here is the event handler