Page 1 of 1

Need help with drop down menu

Posted: Tue Apr 14, 2009 6:01 am
by tacomaniac
Hi
I am trying to create a page with two menu systems.
First I have a jump menu, and below this I have the main menu system.
The thing is to use the jump menu to make a selection of the main menu.
The main menu will link to pages with presentations of information.

E.g. main menu shows:
Topic 1
Topic 2
Topic 3
..
..
Topic 8

And the jump menu will let you choose which choices shall be available in the main menu:
*All slides (main menu will contain links to all topics)
*Topic 1 - 2 (main menu will contain links to topics 1 and 2)
*Topic 3 - 5 (main menu will contain links to topics 3 to 5)
*Topic 6 - 8 (....)
and so on...

I've been forth and back, and now I'm back to basic, with only my drop down menu.

Code: Select all

 
<?php
  $category = array(
    1=> "Show all",
    2=> "Choice 1",
    3=> "Choice 2",
    4=> "Choice 3",
    5=> "Choice 4",
  );
$category = str_replace(" ", " ", $category);
echo '<SELECT name=category>';
foreach ($category as $key => $value)
  {
    echo '<OPTION value='.$value.'> '.$value.'';
  }
  echo '</select>';
 
?>
 
And I think of doing something in the direction of this:

Code: Select all

 
<?php
  if($key == 1){
    include("menu.php");
  }
  elsif($key == 2){
    include("menuchoice1.php");
  }
  /*and so on...*/
?>
 
It is important that the value pulled from the drop down menu will be remembered even if the page is refreshed (reloaded). This is because the main menu have to remain the same for as long as no interaction has been done to the drop down menu.

Hope you understand my problem, let me know if anything is unclear.
I'm quite new to this, so please have patience :)

Regards,
Cato

Re: Need help with drop down menu

Posted: Tue Apr 14, 2009 11:07 am
by Christopher
You could create a function like this:

Code: Select all

function form_select($name, $options, $value) {
  $str = '<select name="'.$name.'">';
  foreach ($category as $key => $val)
    {
      $str .= '<option value="'.$key.'"';
      if ($val == $value) {
        $str .= ' selected="selected"';
      }
      $str .= '> '.$val.'</option>';
    }
    $str .= '</select>';
    return $str;
  }
 
}
Then just pass it the name and options, plus the value from $_POST (if it isset() ). It will set the <select> to the right option.