Can't display selected filed using same code

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
I am a novice and wonder how to show the selected country in the pull down menu in a new page after it is selected by the user. The following code does work where it redirects the user to the new page. The problem is, United States is always selected in this code. How do I make it flexible such that when the same code is run by the new page, that the selected country would show in the pull down box?

<code>

<form name="frmCountry" method="post">

<td align="right" valign="center">Select:&nbsp

<select name="redirCountry" style="font-family:Verdana;font-size:11px;width:130px;">
<option value="us" selected>  United States</option>
<option value="us">  Australia</option>
<option value="es">  Argentina</option>
</select>
</td>

<td><a href="#" onClick="redir = document.frmCountry.redirCountry.options[document.frmCountry.redirCountry.selectedIndex].value; window.location = 'index.php?flag='+redir;"><img src="images/go.gif"></a></td>

</form>

</code>

I'd appreciate if you can show me the modification that can be made to this code to make it work.
 
You have to set the option you want selected using the "selected" attribute. So for each item in your select box, test $_POST['redirCountry'] to see what country was selected, and if it's the correct country, set the selected attribute for that option to "selected".
 
Back
Top