I have 2 select boxes in the same fieldset. I am adding an option to both using jquery and I want them both to have the same default value.
$(function(){
var selectbox = $('.selectbox select');
selectbox.prepend('<option value="Select a question" selected="selected">Select a question</option>');
selectbox.children('option').each(function() {
var option = $(this);
option.removeAttr('disabled');
});
});
I even try to remove the disabled attribute that it sets and I can’t seem to figure out why its setting the second selectbox as disabled for the option.
You have to
prependthe option to eachselectusing.each()loop like below:Your code add
optionto oneselect. And you don’t need todisablethem forprependpurpose.DEMO
Note
If your
optionhasdisabledattribute, I think this should not make any problem with above code. SEE HERE.And to remove
disabledattribute from alloptionyou can do:DEMO