Jump to content

[SOLVED] dropdown menu <selected name="...


agge

Recommended Posts

I have a dropdown menu like this one:

 

<select name="country" tabindex="6" id="select_country">
		<option value="">- Country List -</option>
		<?php 
		$query = "SELECT * FROM country ORDER BY country ASC";
		$result = mysql_query($query) or die('Error, query failed');
		while ($row = mysql_fetch_array ($result)) {
		$country = $row['country'];
		 ?>			
<option value="<?php echo $country ?>"><?php echo $country ?></option>

 

After I have selected one country and I hit the submit button it go back to the default value in the box, what I want is to show the selected value in box until I selected another value.

 

If the default value is Australia when I start this page, I then select USA and hit the submit button it reset to the default value "Australia", but I want it to show USA as long I not select anything else.

 

I have tried to use session in

selected="<?php echo $_SESSION['country']; ?>" 

but it didnt work.

 

Anyone for a solution?

 

 

Link to comment
https://forums.phpfreaks.com/topic/45469-solved-dropdown-menu/
Share on other sites

<select name="country" tabindex="6" id="select_country">
		<option value="">- Country List -</option>
<option value="<?php echo $_GET['country'] ?>"><?php echo $_GET['country'] ?></option>
		<?php 
		$query = "SELECT * FROM country ORDER BY country ASC";
		$result = mysql_query($query) or die('Error, query failed');
		while ($row = mysql_fetch_array ($result)) {
		$country = $row['country'];
		 ?>			
<option value="<?php echo $country ?>"><?php echo $country ?></option>

 

How bout somethin like this

Link to comment
https://forums.phpfreaks.com/topic/45469-solved-dropdown-menu/#findComment-220763
Share on other sites

None of your example did solve my question, BUT it helped me to find the solution to how I should do...

 

So thanks..

<select name="country" tabindex="6" id="select_country">
<option value="">- Country List -</option>
[b]<option value="<?php echo $_SESSION['country']; ?>" selected="<?php echo $_SESSION['country']; ?>"><?php echo $_SESSION['country']; ?></option>[/b]

 

Link to comment
https://forums.phpfreaks.com/topic/45469-solved-dropdown-menu/#findComment-220832
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.