Select (Dropdown) List Generator

Description: Makes a dropdown (SELECT) list.

<?PHP
 
/*  formDropDown  -  create  an  HTML  <select>
  *  vars:  $name  -  the  form  variable  NAME
  *              $value  -  the  SELECTED  option
  *              $labels  -  assoc.  array,  list  of  values=>labels
  *  returns:  string,  HTML  (i.e.  for  use  in  echo  or  print  statement)
  */
FUNCTION  formDropDown($name,$value,$labels)  {
        $html  =  "<select  NAME=\"$name\">\n";
        $key  =  KEY($labels);
        WHILE($key  !=  "")  {
                IF  ($key  ==  $value)  {
                        $selected  =  "SELECTED";
                }  ELSE  {
                        $selected  =  "";
                }
                $html  .=  "<option  VALUE=\"$key\"  $selected>$labels[$key]\n";
                NEXT($labels);
                $key  =  KEY($labels);
        }
        $html  .=  "</select>\n";
        RETURN  $html;
}
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.