Jump to content

Drop down box- How do I?


lilman

Recommended Posts

My objective is that I have a drop down box (a list of categories) and a user can select a category click "Go" and then view a list of all the titles in that category.  I would like the drop down box to stick on the category that the user has chosen to view; however, when the user clicks go and it returns to the page it just shows the first item on the drop down box.

I am hoping that was a clear explanation of what I want to achieve. Could anybody help me?
Link to comment
https://forums.phpfreaks.com/topic/28923-drop-down-box-how-do-i/
Share on other sites

On the page that receives the POSTED form the value of the selected item will be available as $_POST['category'] (or whatever you named the field).

Since you did not show where you get the values for the select list I will assume it is from a database query or in an array. Here is an example of how it can be done assuming the select items are in an array:
[code]<?php

echo "<select name=\"category\">";

foreach ($categorylist as $option) {
    echo "<option value=\"".$option."\" ";
    echo ($option==$_POST['category']) ? " selected" : "";
    echo ">".$option."</option>";
}

echo "</select>";

?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.