Changing a select menu with Jquery when radio is checked
Hi i seem to be having a little problem with my code and was wondering is someone could point me in the right direction with it.
What i am doing is if a radio button is selected it will show a different set of city names.
My Jquery code is as follows :
- $(function() {
- $( "#accordion" ).accordion({
- collapsible: true
- });
- $( "#citta_az" ).buttonset();
-
- //Hide Monza e Brianza when page loads
- $("#MB_DIV").css("display","none");
- // Click Function
- $("#citta_az_mb").click(function(){
- // If MB Is checked
- if ($("#citta_az_mb").is(":checked"))
- {
- //show Monza e Brianza Città
- $("#MI_DIV").hide("fast");
- $("#MB_DIV").show("fast");
-
- }
- //Else if MI is checked
- else if ($("#citta_az_mi").is(":checked"))
- {
- //otherwise, hide it
- $("#MB_DIV").hide("fast");
- $("#MI_DIV").show("fast");
- }
- });
- });
My HTML Code is as follows :
- <input name="citta_az" type="radio" id="citta_az_mi" value="MI" checked><label for="citta_az_mi">MI </label>
-
- <input name="citta_az" type="radio" id="citta_az_mb" value="MB">
- <label for="citta_az_mb">MB</label>
- <div id="MB_DIV">
- <select name="citta_az_mb" id="citta_az_mb">
- <?php
- foreach ($_Citta_MB as $pts => $name)
- {
- echo '<option value="'.$pts.'">'.$name.'</option>';
- }
- ?>
- </select>
- </div>
- <div id="MI_DIV">
- <select name="citta_az_mi" id="citta_az_mi">
- <?php
- foreach ($_Citta_MI as $pts => $name)
- {
- echo '<option value="'.$pts.'">'.$name.'</option>';
- }
- ?>
- </select></div>
The problem i am having is that when i click MB it will show mb but if i click MI again it will not show again.
I hope someone can help with this.
Thanks