Jump to content


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


How do I maintain Drop Down Menu Selections?

Recommended Posts

Hi everyone,

I'm new here and consequently new to php. :)

My problem right now lies with using the drop down menus. I have on my page two drop down menus. You make a selection from the first drop down menu. Once you've made your selection you then make a selection from the second drop down menu. This second drop down menu is populated with choices that are based on your first selection. There is a "submit" button for each drop down menu.

The issue is that when I make my selection from the first drop down menu and press 'submit', the choice that I made does not stay visible in the drop down menu. It goes immediatley back to the first option of the drop down menu. It's almost as if the page is being refreshed each time I press the 'submit' button! I want to be able to stop this because I want users to be able to view each selection that they have made.

Can anyone help?


Share this post

Link to post
Share on other sites
Mags --

I hope you get a better answer than mine, because I can't think of how you can do this with straight PHP. I know it would be possible with Javascript, though. I have seen these before where it changes the second menu as soon as you select the first one, not with a submit button.

With straight PHP & hitting a submit button, the only thing I could think of is to have Switch statements to move through or something, where once you hit submit, the previous selection grays out or becomes just text, and you would have links to go back & reenter a previous selection.

But I'm not sure if that would work for what you're doing (does what I'm saying make sense?).


Share this post

Link to post
Share on other sites
Pretty simple to do:
Here's an example.

[code]<select name="Number" id="Number">
$num_array = range(1,5);
if (!isset($_POST['Number'])) { $Num = 1; } else { $Num = $_POST['Number']; }

foreach ($num_array as $number)
echo '<option value="'.$number.'"';
if ($Num == $number) { echo " selected=\"selected\""; }
echo '>'.$number.'</option>';
} ?></select>[/code]

Share this post

Link to post
Share on other sites


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.