Jump to content

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


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.