List/Menu - dynamic initial value for menu

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ender22
Forum Newbie
Posts: 8
Joined: Thu Apr 12, 2007 11:15 am

List/Menu - dynamic initial value for menu

Post by Ender22 »

Hello.

I have a php form with a few fields and one of the fields is a menu called category, where the user can select a category.
The initial value for the category is 'other'
also on my form is a preview button which takes the user to a new page where they can view all of their data before submitting it.

My problem is, when they move to this new page to view all of their data, I can pass in all of the new data to show them including the category they chose... however I dont know how to set the menu to display that category automatically. It always reverts back to the value 'Other' because I dont know how to set a dynamic initial value for it.

Incase im not being clear heres an example.

-Users fills out a form and chooses entertainment (with a value of 5) as the category
-they hit submit
-the value 5 is passed to the new page
-however when the submit form comes up entertainment is not selected as the category by default because I cant set the initial value of the menu to 5

is there any parameter or php code or anything on a menu to set the inital value dynamically. As far as I know it only lets you select a default initial value like this:

Code: Select all

<select name="Category" id="Category">
                      <option value="0">Animal / Nature</option>
                      <option value="1">Automotive</option>
                      <option value="2" selected>Other</option> // with this being the default init value
                    </select>
any help is greatly appreciated!

thanks!
Ender22
Forum Newbie
Posts: 8
Joined: Thu Apr 12, 2007 11:15 am

Post by Ender22 »

Hey!

The act of posting the message enabled me to figure it out! :lol:

Heres what I did incase anyone else needs this:

Code: Select all

<select name="Category" id="Category">
                      <option value="0"<?php if($category == 0) echo "selected"; ?>>Animal / Nature</option>
                      <option value="1"<?php if($category == 1) echo "selected"; ?>>Automotive</option>
                      <option value="2" <?php if($category == 2) echo "selected"; ?>> Business</option>
                    </select>
hope it helps someone!
Post Reply