lilman Posted November 29, 2006 Share Posted November 29, 2006 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 More sharing options...
Psycho Posted November 30, 2006 Share Posted November 30, 2006 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]<?phpecho "<select name=\"category\">";foreach ($categorylist as $option) { echo "<option value=\"".$option."\" "; echo ($option==$_POST['category']) ? " selected" : ""; echo ">".$option."</option>";}echo "</select>";?>[/code] Link to comment https://forums.phpfreaks.com/topic/28923-drop-down-box-how-do-i/#findComment-132458 Share on other sites More sharing options...
lilman Posted November 30, 2006 Author Share Posted November 30, 2006 Very simple, I appreciate your help ;D Link to comment https://forums.phpfreaks.com/topic/28923-drop-down-box-how-do-i/#findComment-132489 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.