I have 4 dropdowns and when 1 is selected, I want the other 3 to reset to the first option in the dropdown. I have the code below and it doesn’t work.
$(document).ready(function() {
$('select').change(function() {
var current = $(this).attr('id');
$('select').each(function() {
if(!$(this).attr('id') == current) {
$('select option:eq(0)').attr('selected', true);
}
});
});
});
<h:selectOneMenu value="#{selectCategory.currentCategory}"
valueChangeListener="#{selectCategory.valueChanged}" id="menu2">
<f:selectItems value="#{selectCategory.national}" />
<a4j:ajax event="valueChange" execute="@this"
oncomplete="loadDataAndCreateChart()" />
</h:selectOneMenu>
<h:selectOneMenu value="#{selectCategory.currentCategory}"
valueChangeListener="#{selectCategory.valueChanged}" id="menu3">
<f:selectItems value="#{selectCategory.industry}" />
<a4j:ajax event="valueChange" execute="@this"
oncomplete="loadDataAndCreateChart()" />
</h:selectOneMenu>
<h:selectOneMenu value="#{selectCategory.currentCategory}"
valueChangeListener="#{selectCategory.valueChanged}" id="menu4">
<f:selectItems value="#{selectCategory.mayo}" />
<a4j:ajax event="valueChange" execute="@this"
oncomplete="loadDataAndCreateChart()" />
</h:selectOneMenu>
equals to
<select id="menu1" name="menu1" size="1" onchange="RichFaces.ajax(this,event,{"sourceId":"menu1","parameters":{"javax.faces.behavior.event":"valueChange"} } )"> <option value="1" selected="selected">1</option>
<option value="2">2</option>
<option value="3">3Grant</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select><select id="menu2" name="menu2" size="1" onchange="RichFaces.ajax(this,event,{"sourceId":"menu2","parameters":{"javax.faces.behavior.event":"valueChange"} } )"> <option value="1" selected="selected">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select><select id="menu3" name="menu3" size="1" onchange="RichFaces.ajax(this,event,{"sourceId":"menu3","parameters":{"javax.faces.behavior.event":"valueChange"} } )"> <option value="1" selected="selected">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select><select id="menu4" name="menu4" size="1" onchange="RichFaces.ajax(this,event,{"sourceId":"menu4","parameters":{"javax.faces.behavior.event":"valueChange"} } )"> <option value="1" selected="selected">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
My first thought is that something like the following should work (though it is, as yet, untested):
JS Fiddle demo.