Thank's for the help! Dean ----- Original Message ----- From: "Jimmy" <[EMAIL PROTECTED]> To: "Dean Householder" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Sunday, January 13, 2002 12:33 AM Subject: Re: [PHP] Piping data into a select box
> Hi Dean, > > > Does anyone know how to give a select pulldown box a default value > > from a PHP variable? > > <? > function generate_option_list ($key_value,$set) { > // This function will return option list and set the selected attribute > // $key_value : the associative array which contain the key and the value for each option > // $set : the value to be selected by deafult > // > // Usage: for example we want to have a dropdown list of month, and set February as selected > // > // $key_value=array("01"=>"January","02"=>"February",...); > // $option_list=generate_option_list($key_value,"02"); > // //$option_list now contain text <option value='01'>January</option> > // // <option value='02' selected>February</option> > // > // NOTE: This will only create the <OPTION> tag, without the <SELECT> tag > // > > while ( list($key,$value) = each($key_value) ) { > if ($key==$set) {$var.="<option value='$key' selected>$value</option>";} > else {$var.="<option value='$key'>$value</option>";} > } > return $var; > } > > ?> > > -- > Jimmy > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Leave loved ones with loving words, it may be the last time you see them > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]