MagsK Posted June 15, 2006 Share Posted June 15, 2006 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?Cheers,Mags Quote Link to comment https://forums.phpfreaks.com/topic/12089-how-do-i-maintain-drop-down-menu-selections/ Share on other sites More sharing options...
WendyLady Posted June 15, 2006 Share Posted June 15, 2006 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?).Wendy Quote Link to comment https://forums.phpfreaks.com/topic/12089-how-do-i-maintain-drop-down-menu-selections/#findComment-46031 Share on other sites More sharing options...
annihilate Posted June 15, 2006 Share Posted June 15, 2006 Pretty simple to do:Here's an example.[code]<select name="Number" id="Number"><?php $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] Quote Link to comment https://forums.phpfreaks.com/topic/12089-how-do-i-maintain-drop-down-menu-selections/#findComment-46055 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.