I have a drop-down navigation that brings the user to the page selected in the drop-down once the user clicks a button. I have a function that takes in the page section title as a parameter and builds a new drop-down with that page on top of the list, so that each page you navigate to will remain in focus in the drop-down. The function is a massive switch case with a lot of repetitive code and I know there’s an easier and cleaner way of doing this… I’m just having trouble thinking of a solution. Here’s a code snippet, I won’t post the entire switch case:
function makeDropDown($page){
switch ($page){
case 'uploads':
echo '<center><form action="pictures.php" action="get">
<select name="pictype">
<option value="uploads">Uploads</option>
<option value="fromweb">From Web</option>
<option value="wallpapers">Wallpapers</option>
<option value="misc">Miscellaneous</option>
</select>
<input type="submit" value = "Go!"/>
</form></center>'; break;
case 'fromweb':
echo '<center><form action="pictures.php" action="get">
<select name="pictype">
<option value="fromweb">From Web</option>
<option value="uploads">Uploads</option>
<option value="wallpapers">Wallpapers</option>
<option value="misc">Miscellaneous</option>
</select>
<input type="submit" value = "Go!"/>
</form></center>'; break;
case 'wallpapers':
echo '<center><form action="pictures.php" action="get">
<select name="pictype">
<option value="wallpapers">Wallpapers</option>
<option value="uploads">Uploads</option>
<option value="fromweb">From Web</option>
<option value="misc">Miscellaneous</option>
</select>
<input type="submit" value = "Go!"/>
</form></center>'; break;
Any suggestions?
Instead of moving the selected item to the top of the list, why not try using the
selectedattribute of the option items. This will initialize the select box to the selected option. simply echoselectedin the option that matches the value of$pageThis way, if
$page=='misc', your HTML will result this way