Reputation: 25
currently my drop down only disables (greys out) when radio button 'No' is selected. How do I disable drop down when nothing is selected aswell? colour and shade are the names of my 2 drop down menus.
$("input[name^='attendance']").click(function() {
var id = this.name.replace('attendance', '');
$("#colour" + id + ", #shade" + id).prop("disabled", this.value == 'No');
Upvotes: 1
Views: 381
Reputation: 491
I think there is a more fundamental problem here as this code will never be executed in the way you expect. This is in the onClick event of the radio, meaning that it will always have a state (Yes/No).
You'll need to do this in two statements, something like this maybe?
$("input[name^='attendance']").click(function() {
var id = this.name.replace('attendance', '');
$("#colour" + id + ", #shade" + id).prop("disabled", this.value == 'No');
...
});
$("#colour" + id + ", #shade" + id).prop("disabled", !$(input[name^='attendance').val());
Upvotes: 1
Reputation: 16223
This should work for you:
$("#colour" + id + ", #shade" + id).prop("disabled", this.value == 'No' || ! this.value );
Upvotes: 0
Reputation: 14747
I imagine maybe something like this?
$().prop('disabled', !this.value || this.value == 'No');
Upvotes: 0