vendredi 27 février 2015

Can not figure out why my Select Dropdown only updates once

I am using JQuery to update the defualt option of a select dropdown based on the value of another select dropdown. For some reason the update only works on the first change and I can not figure out why.


HTML:



<label>Enclosure Type:</label>
<select name="enclosure_type_it">
<option value="global">Global </option>
<option value="server_optimized">Server Optimized </option>
</select>
<div class="pure-control-group">
<label>Handles:</label>
<select name="handles_it" id="handles_datacenter">
<option value="Semi Cylinder">Semi Cylinder</option>
<option value="Combo_Security Handle">Combo/Security Handle </option>
<option value="Comfort Handle">Comfort Handle </option>
</select>
</div>
<div class="pure-control-group">
<label>Inserts:</label>
<select name="inserts_it" id="inserts_datacenter">
<option value="Pushbutton">Pushbutton </option>
<option value="Locking pushbutton">Locking pushbutton </option>
<option value="Locking">Locking </option>
</select>
</div>


JQuery:



$('#enclosure_type_it').change(function() {
if ($(this).val() == "global") {
$('#handles_datacenter option[value="Semi Cylinder"]').attr("selected", true);
$('#inserts_datacenter option[value="Locking"]').attr("selected", true);
}
if ($(this).val() == "server_optimized") {
$('#handles_datacenter option[value="Comfort Handle"]').attr("selected", true);
$('#inserts_datacenter option[value="Locking pushbutton"]').attr("selected", true);
}
}).change();

Aucun commentaire:

Enregistrer un commentaire