Re: Piping data into a select box

From: Date: Sun, 13 Jan 2002 08:26:10 +0000
Subject: Re: Piping data into a select box
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-80338@lists.php.net to get a copy of this message
Thank's for the help! Dean ----- Original Message ----- From: "Jimmy" <jimmy@spacedisk.com> To: "Dean Householder" <dean@adoption.com> Cc: <php-general@lists.php.net> 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 > > >

« previous php.general (#80338) next »