Jump to content

Select default


KingOfHeart

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/214465-select-default/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/214465-select-default/#findComment-1116008
Share on other sites

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.