I have 2 drop down menus, I want this: when I choose option in the dropdown menu called “ItemCountry”, the div id=”StateFeeder” will load a certain dropdown menu in another page according to the value in the first menu.
this is the first menu:
<label for="ItemCountry">Country <span class="req">*</span></label>
<select name="ItemCountry" id="ItemCountry" class="cat_dropdown" onblur="StateFeeder()">
<option value=" ">-- Select Country --</option>
<option value="AU" selected="selected">Australia</option>
<option value="CA">Canada</option>
<option value="CN">China</option>
<option value="NZ">New Zealand</option>
<option value="RU">Russia</option>
<option value="US">United State</option>
</select>
and this is the second menu:
<div id="StateFeeder">
<div>
<label for="ItemState">State <span class="req">*</span></label>
<select name="ItemState" id="ItemState" class="cat_dropdown">
<option value="">-- Please select --</option>
<option value="NSW">NSW</option>
<option value="VIC">VIC</option>
<option value="QLD">QLD</option>
<option value="ACT">ACT</option>
<option value="TAS">TAS</option>
<option value="WA">WA</option>
<option value="SA">SA</option>
<option value="NT">NT</option>
</select>
e.g. NSW
</div>
</div>
the jquery I wrote but it is not working:
<script type="text/javascript">
$(function() {
$('#ItemCountry').change(function() {
if (document.ItemCountry.selectedIndex == 'AU') {
$("#StateFeeder").empty().html('<img src="/images/mapCountry /AU/ajaxloader.gif" class="IMG-Loading" />');
$('#StateFeeder>div').load('/StateFeeder/StateFeeder-Buy.html #StateFeeder-AU');
};
if (document.ItemCountry.selectedIndex == 'CA') {
$("#StateFeeder>div").empty().html('<img src="/images/mapCountry/AU/ajax-loader.gif" class="IMG-Loading" />');
$('#StateFeeder').load('/StateFeeder/StateFeeder-Buy.html #StateFeeder-CA');
};
if (document.ItemCountry.selectedIndex == 'CN') {
$("#StateFeeder").empty().html('<img src="/images/mapCountry/AU/ajax-loader.gif" class="IMG-Loading" />');
$('#StateFeeder').load('/StateFeeder/StateFeeder-Buy.html #StateFeeder-CN');
};
if (document.ItemCountry.selectedIndex == 'NZ') {
$("#StateFeeder").empty().html('<img src="/images/mapCountry/AU/ajax-loader.gif" class="IMG-Loading" />');
$('#StateFeeder').load('/StateFeeder/StateFeeder-Buy.html #StateFeeder-NZ');
};
if (document.ItemCountry.selectedIndex == 'RU') {
$("#StateFeeder").empty().html('<img src="/images/mapCountry/AU/ajax-loader.gif" class="IMG-Loading" />');
$('#StateFeeder').load('/StateFeeder/StateFeeder-Buy.html #StateFeeder-RU');
};
if (document.ItemCountry.selectedIndex == 'US') {
$("#StateFeeder").empty().html('<img src="/images/mapCountry/AU/ajax-loader.gif" class="IMG-Loading" />');
$('#StateFeeder').load('/StateFeeder/StateFeeder-Buy.html #StateFeeder-US');
};
});
});
</script>
selectedIndexreturns the index of the selected option, you should use thevalueproperty: