Alex Briffett Life is just a state of mind

14Jan/100

Simple PHP Function to Maintain Drop-Down State

This PHP function is a quick, simple way to maintain the state of select / drop downs when the form input is invalid.

/**
* Function to draw drop down boxes and allow the state to be maintained
* if the form has an error
*
* @param array $vals - select box values
* @param array $text - select box show values
* @param string $search - the name/id of the select box to be searched for
*/
function dropDown( $vals, $text, $search )
{
for ($i=0; $i < count($vals); $i++)
{
if ($search == trim($vals[$i]))
{
$selected = "selected=\"selected\"";
}
else
{
$selected = "";
}
$result .= "$text[$i]\n";
}
return ($result);
}
?>

Filed under: Web Code Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.