Jump to content


Photo

How do I maintain Drop Down Menu Selections?


  • Please log in to reply
2 replies to this topic

#1 MagsK

MagsK
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 15 June 2006 - 06:13 PM

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

#2 WendyLady

WendyLady
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 15 June 2006 - 06:32 PM

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

#3 annihilate

annihilate
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts
  • LocationUK

Posted 15 June 2006 - 07:51 PM

Pretty simple to do:
Here's an example.

<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>

Personal site: NewEnigma  |  Java and JSF Discussion




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users