Link to home
Start Free TrialLog in
Avatar of birdy_carolyn
birdy_carolyn

asked on

Choosing a radio button to populate a dropdown box: How to set dropdown to remember selection?

Hello Everyone,

I've modified the following bit of code for my purposes.  I'm very new to Javascript and was happy that I could even get this working so I'd appreciate any help that anyone can provide!

I currently have a set of radio buttons that respond to the function below.  When the user selects a radio button, the main dropdown box is populated with the selection.  The user then presses a 'refresh' button to submit their information.  

My issue is that we are using ASP to program most of the page and session variables to store the users selections.  In other dropdown boxes we use we can store the users selection so that once they press refresh, their selection is now the 'active' one in the dropdown box.

We'd like to do the same for the dropdown boxes that are populated by radio buttons, however I don't have a clue of where to begin.  Unfortunately, we really need to use the radio buttons and the following method is the only way I got it working.

If anyone has any ideas of how we can keep the users selection in the dropdown box, I'd love to hear it.

Thanks,
Carolyn




RADIO BUTTON
<input type="radio" name="type" value="MilitaryAirfield" onclick="reLoad(this.value);" />Military Airfields<br>

DROP DOWN
<select name="timeSel"><option value="<%=strRoute%>"><%=strRoute%></select>

FUNCTION
function reLoad( v ) {
    var sma;
    if (v == 'VRoute') sma = VR;
    else
      if (v == 'IRoute') sma = IR;
          else
            if (v == 'SRoute') sma = SR;
                else
                  if (v == 'MOArea') sma = MOA;
                      else
                        if (v == 'MilitaryAirfield') sma = MilAir;
                            else

                              if (v == 'Ranges') sma = Range;
                                  else

                                    if (v == 'CivilAirfield') sma = Civil;
                                        else

                                          if (v == 'Cities') sma = City;
                                              else
                                                
                                                if (v == 'LatLong') sma = LL;
                                                    

    var s = document.forms['frmNavigation'].elements['timeSel'];
    s.options.length = 0;

    for (var i = 0; i < sma.length; i++ ) {
        s.options[i] = new Option( sma[i], sma[i]);
    }

}
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial