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.
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