Re: Piping data into a select box

From: Date: Sun, 13 Jan 2002 07:33:17 +0000
Subject: Re: Piping data into a select box
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-80334@lists.php.net to get a copy of this message
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

« previous php.general (#80334) next »