Here is a function to generate a select box for a HTML form. The three parameters are:
- $name : The name of the select, this will appear in the "name" attribute.
- $options : An associative array containing all of the options.
- $default : The option that will be selected as default.
function generateSelect($name,$options,$default=''){ $html = ''; foreach ($options as $value => $label) { $html .= '' . $label . ''; } $html .= ''; return $html; }
You can call the function like this:
echo generateSelect('selectPreference',array('yes'=>'yes','no'=>'no'),'yes');
Which produces the following HTML as output:
yesno
0 comments:
Post a Comment