Posted by zorro on 05/22/06 06:50
this will handle select lists
<?
$myOptions=array();
$myOptions['color1']='blue';
$myOptions['color2']='red';
?>
<select name="optList">
<option value="">Pick one</option>
<? displayOptionList($myOptions,"optList"); ?>
</select>
<?
function displayOptionList($options,$inputName){
if($_POST)
{
foreach($options as $key=>$value)
{
if($_POST["$inputName"]==$key)
{ echo "<option value=\"$key\" selected>$value</option>";
}
else
{ echo "<option value=\"$key\">$value</option>";
}
}
}
else
{
foreach($options as $key=>$value)
{ echo "<option value=\"$key\">$value</option>";
}
}
}
?>
[Back to original message]
|