– – edited as i described it incorrectly first time round, sorry! – –
Hi,
i am trying to use show/hide to manipulate what is shown in a second dropdown menu, based on what is selected in the first dropdown menu. However after having it work briefly, it now doesn’t across any browser, it just shows them all no matter what is selected. When an option is selected in the first menu, it needs to then display particular options in the second menu. Each airport has it’s own set of destinations. Unfortunately there isn’t a php/mysql database option for this :/
the js is as follows:
$(document).ready(function(){
$("#from_BLANK").click(function () {
$("#to_A1").show();
$("#to_A2").show();
$("#to_A3").show();
});
$("#from_A1").click(function () {
$("#to_A1").hide();
$("#to_A2").show();
$("#to_A3").show();
});
$("#from_A2").click(function () {
$("#to_A1").show();
$("#to_A2").hide();
$("#to_A3").show();
});
$("#from_A3").click(function () {
$("#to_A1").show();
$("#to_A2").show();
$("#to_A3").hide();
});
});
And the html on the dropdowns is as follows:
<select name="depApt" id="depApt">
<option id="from_BLANK" selected="selected"> </option>
<option id="from_A1" value="A1">Airport One</option>
<option id="from_A2" value="A2">Airport Two</option>
<option id="from_A3" value="A3">Airport Three</option>
</select>
<select name="dstApt" id="dstApt">
<option id="to_BLANK" selected="selected"> </option>
<option id="to_A1" value="A1">Airport One</option>
<option id="to_A2" value="A2">Airport Two</option>
<option id="to_A3" value="A3">Airport Three</option>
</select>
Are there any glaring errors? or maybe better ways to achieve this?
Any and all help most appreciated!
cheers,
Paul
Here’s the script which will prevent both dropdown from being the same other than both are blank. The option in B will always be disabled if the corresponding one in A is selected.
Tested in IE8 and FF3.5 and Chrome.
Javascript:
HTML:
PS: I’ve removed all the IDs of the options as they are not required for my codes, restore it back if needed.