Jump to content

How do I maintain Drop Down Menu Selections?


MagsK

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?

Cheers,
Mags
Link to comment
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?).

Wendy
Link to comment
Share on other sites

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]
Link to comment
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.