KingOfHeart Posted September 26, 2010 Share Posted September 26, 2010 I have a few dropdown forums and would like it to select the current values that are requested. global $filename,$fileid,$filetype,$filedir,$fileby; global $months,$pg; echo "<h2>Search Files</h2>"; echo "<p>"; echo "<form name = 'File_Search' action = '#' method = 'POST'>"; echo "<table border=\"0\" width=\"100%\"><tr>"; echo "<td>File Name<br><input type = 'text' name = 'name'></td><td>File Type<br><select name = 'type'> <option value = '0'>All Types</option> <option value = 'o'>Official Files</option> <option value = '1'>Quests</option> <option value = '2'>Graphic/Spritesheets</option> <option value = '3'>Entity/Scripts</option> <option value = '4'>Sound/Music</option> <option value = '5'>QuestPack/Programs</option> <option value = '6'>Miscellaneous</option> </select></td>"; echo "<td>Order By<br><select name = 'order'> <option value = '0'>Last Updated</option> <option value = '1'>ID</option> <option value = '2'>Name</option> <option value = '3'>Downloads</option> <option value = '4'>Rating</option> <option value = '5'>Points</option> <option value = '6'>Random</option> </select></td>"; echo "<td>Acending?<br><select name = 'dir'><option value = '0'>False</option><option selected value = '1'>True</option></select></td>"; echo "</tr><tr><td rowspan = '4'><input type = 'submit' name = 'search' value = 'search'></td></tr></table></form>"; echo "</p>"; So if the $filetype equals 2 I want the dropdown box to show "Graphic/Spritesheets" by default. BTW Official Files is not actually a type so that's why I chose to give it a small letter o and will work the same way as All Types but run a different function. $fileby is used for the OrderBy field. $filedir is for the Acending field. The other data is for the other parts of the script. If you like you can give advice on the name's default because you may have a better method then what I have in my head. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted September 26, 2010 Share Posted September 26, 2010 FYI: You'll run into problems having a form element with name='name' to select the selected, i use something like this: <option value = '1' <?php if ($type == 1) { echo "selected='selected'"; } ?>>Quests</option> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 26, 2010 Share Posted September 26, 2010 Store the options in arrays, then loop through with foreach to build the <option></option> tags. While looping check to see if the array index equals the variable for that <select>, and if so, echo selected="selected" within the <option> tag. Make sense? Quote Link to comment Share on other sites More sharing options...
rwwd Posted September 26, 2010 Share Posted September 26, 2010 FYI: You'll run into problems having a form element with name='name' T'is a reserved word I believe... Rw Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.