Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML HTML Basics

Can't display selected filed using same code

Discussing Html . Code , Software , other

Moderators: macek, egami, gesf

Can't display selected filed using same code

Postby neofinder » Thu Oct 28, 2004 8:23 pm

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>&nbsp; United States</option>
<option value="us">&nbsp; Australia</option>
<option value="es">&nbsp; 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.
neofinder
New php-forum User
New php-forum User
 
Posts: 6
Joined: Wed Oct 27, 2004 9:23 am

Postby swirlee » Fri Oct 29, 2004 8:30 am

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".
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back


Return to HTML Basics

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.