HTML Dropdown Menu Generator
<?php
function fnDisplay_DropDown($aFields, $sName, $sSel=NULL, $sClass=NULL, $sID=NULL)
{
if(empty($aFields) || empty($sName))
die("Parameter missing in call to fnDisplay_DropDown()");
if(!(is_array($aFields)))
die("Array passed to fnDisplay_DropDown() is in invalid format.");
$sHTML = sprintf(" <select name=\"%s\"%s%s>\n", $sName,
!empty($sClass) ? " class=\"$sClass\"" : $sClass,
!empty($sID) ? " id=\"$sID\"" : $sID);
foreach($aFields as $sVar=>$sVal)
{
$sSelect = NULL;
if($sVar === $sSel)
$sSelect = " selected=\"selected\"";
$sHTML .= sprintf(" <option value=\"%s\"%s>%s</option>\n",
$sVar, $sSelect, htmlspecialchars($sVal));
}
$sHTML .= sprintf(" </select>\n");
return $sHTML;
}
?>