Reputation: 705
I want to disable radio buttons based on the value of a variable. The radio that is equal to the variable value should be disabled.
Ex:
<input type="radio" name="r1" value="a" />Value a
<input type="radio" name="r1" value="b" />Value b
So if the $variable = 'a';
then the radio button which has the value a
should be disabled.
Upvotes: 7
Views: 27597
Reputation: 109
If you want to disable based by name and value, you can try this
var a = 'a';
var fieldName = 'r1';
$('input[type=radio][name=' + fieldName + '][value='+ a +']').prop('disabled', true);
Upvotes: 1
Reputation: 24236
Try -
var a = 'a';
$("input[type=radio][value=" + a + "]").prop("disabled",true);
or
var a = 'a';
$("input[type=radio][value=" + a + "]").attr("disabled",true);
If you're using an older jQuery version.
Working demo - http://jsfiddle.net/FtwcL/1
Upvotes: 19