Re: setting Check box - THANKS!

From: Date: Wed, 28 Mar 2001 03:19:34 +0000
Subject: Re: setting Check box - THANKS!
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-45813@lists.php.net to get a copy of this message
Thanks, that did it. Steve ----- Original Message ----- From: "David Robley" <huntsman@www.nisu.flinders.edu.au> To: <php-general@lists.php.net> Sent: Tuesday, March 27, 2001 7:58 PM Subject: Re: [PHP] setting Check box > On Wed, 28 Mar 2001 10:18, S. Efurd wrote: > > This worked for me as well, and helped me with a problem I was having! > > > > How would you show what option was selected in a drop down box. I have > > a form the user fills out, this goes to a confirmation page to ensure > > the data enetered is correct. I have a drop down box for states, and I > > cant seem to make it show the state selected it always defaults to > > first choice? > > > > Thanks > > I've built a function for displaying drop down lists: yours for free. Oh > look, Ive even bothered to comment it ;-) It will show selected item[s] > > Somebody will no doubt post improvements. > > <?php > /* formDropDown - create an HTML <SELECT> > * vars: $name - the form variable NAME > * $value - the SELECTED option which may be an array for multiple > selected items > * $labels - assoc. array, list of values=>labels > * $multiple - if non-empty, select multiple > * $size - number of rows to show if multiple > * returns: string, HTML (i.e. for use in echo or print statement) */ > > function formDropDown($name,$value,$labels,$multiple = '',$size ='') { > $html = '<SELECT NAME="' .$name . '"'; > if(!empty($multiple)) { > $html .= ' MULTIPLE'; > } > if(!empty($size)) { > $html .= ' SIZE=' . $size; > } > > $html .= ">\n"; > $key = key($labels); > while($key != "") { > /* Check if the current value is in the $value variable */ > if(is_array($value)) { > if(in_array($key,$value)) { > $selected = ' SELECTED'; > } else { > $selected = ''; > } > } else { > if ($key == $value) { > $selected = ' SELECTED'; > } else { > $selected = ''; > } > } > $html .= "<OPTION VALUE=\"$key\"$selected>$labels[$key]\n"; > next($labels); > $key = key($labels); > } > $html .= "</SELECT>\n"; > return $html; > } > ?> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#45813) next »