Reputation: 37909
How do I modify the jquery to use the var instead of the '12'?
var disableId = 12;
if (e.currentTarget.checked) {
$("input:checkbox[value=12]").attr("disabled", true);
}
else {
$("input:checkbox[value=12]").attr("disabled", false);
}
Upvotes: 0
Views: 51
Reputation: 32581
Open the string and add it
$("input:checkbox[value='"+disableId +"']").prop("disabled", true);
also you should use prop() instead of attr for boleean values
Upvotes: 1
Reputation: 128791
You should use jQuery's prop()
method instead of attr()
for boolean values; also there's no need for the IF statements at all as you can just set the disabled
state to equal e.currentTarget.checked
(which is either true
or false
):
var disableId = 12,
state = e.currentTarget.checked;
$("input:checkbox[value='" + disableId + "']").prop("disabled", state);
Upvotes: 1