RE: [PHP] <select name=....

From: Date: Fri, 23 Feb 2001 05:12:43 +0000
Subject: RE: [PHP] <select name=....
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-41262@lists.php.net to get a copy of this message
well...i just finished some code for dealing with an option box that has all the states listed... <select name="state" size="1"> <option value="">Select State</option> <? $ST[] = 'AL'; $ST[] = 'AK'; $ST[] = 'AR'; $ST[] = 'AZ'; $ST[] = 'CA'; $ST[] = 'CO'; $ST[] = 'CT'; $ST[] = 'DC'; $ST[] = 'DE'; $ST[] = 'FL'; $ST[] = 'GA'; $ST[] = 'HI'; $ST[] = 'IA'; $ST[] = 'ID'; $ST[] = 'IL'; $ST[] = 'IN'; $ST[] = 'KS'; $ST[] = 'KY'; $ST[] = 'LA'; $ST[] = 'MA'; $ST[] = 'MD'; $ST[] = 'ME'; $ST[] = 'MI'; $ST[] = 'MN'; $ST[] = 'MO'; $ST[] = 'MS'; $ST[] = 'MT'; $ST[] = 'NC'; $ST[] = 'ND'; $ST[] = 'NE'; $ST[] = 'NH'; $ST[] = 'NJ'; $ST[] = 'NM'; $ST[] = 'NV'; $ST[] = 'NY'; $ST[] = 'OH'; $ST[] = 'OK'; $ST[] = 'OR'; $ST[] = 'PA'; $ST[] = 'PR'; $ST[] = 'RI'; $ST[] = 'SC'; $ST[] = 'SD'; $ST[] = 'TN'; $ST[] = 'TX'; $ST[] = 'UT'; $ST[] = 'VA'; $ST[] = 'VT'; $ST[] = 'WA'; $ST[] = 'WV'; $ST[] = 'WI'; $ST[] = 'WY'; for($i = 0; $i < count($ST); $i++) { echo '<option value="'.$ST[$i].'"'; if($state == $ST[$i]) { echo ' selected'; } echo '>'.$ST[$i]."</option>\n"; }//For ?> </select> First it creates an array $ST that contains a list of all the states (includes PR and DC) Next it loops through that array and if $state has the same value as the state, it selects it... You could probably turn this into a function or something... =codeboy > -----Original Message----- > From: Peter Houchin [mailto:peterh@vfsa.com.au] > Sent: Thursday, February 22, 2001 8:17 PM > To: PHP MAIL GROUP > Subject: [PHP] <select name=.... > > > if i have a form with a select box in it how an i get the values > to echo a php value ... > > ie > > <SELECT NAME="state" SIZE="1"> > <OPTION VALUE="Canberra">ACT</OPTION> > <OPTION VALUE="Victoria">VIC</OPTION> > </SELECT> > > can i change it to say > <SELECT NAME="state" SIZE="1"> > <OPTION VALUE="<? echo $state ?>">ACT</OPTION> > <OPTION VALUE="<?echo $state ?>">VIC</OPTION> > </SELECT> > > so that when the page loads it shows which ever option is in the > Data base? > > Peter Houchin > Sun Rentals > peterh@sunrentals.com.au > >

« previous php.general (#41262) next »