PHP Array to Create State Dropdown List - Need to set specific state to default -
i have plugin using creates dropdown of states using array , loop populate select box. here array
//define state array used generate state select box $usstates = array( "al" => "alabama", "ak" => "alaska", "az" => "arizona", "ar" => "arkansas", "ca" => "california", "co" => "colorado", "ct" => "connecticut", "de" => "delaware", "fl" => "florida", "ga" => "georgia", "hi" => "hawaii", "id" => "idaho", "il" => "illinois", "in" => "indiana", "ia" => "iowa", "ks" => "kansas", "ky" => "kentucky", "la" => "louisiana", "me" => "maine", "md" => "maryland", "ma" => "massachusetts", "mi" => "michigan", "mn" => "minnesota", "ms" => "mississippi", "mo" => "missouri", "mt" => "montana", "ne" => "nebraska", "nv" => "nevada", "nh" => "new hampshire", "nj" => "new jersey", "nm" => "new mexico", "ny" => "new york", "nc" => "north carolina", "nd" => "north dakota", "oh" => "ohio", "ok" => "oklahoma", "or" => "oregon", "pa" => "pennsylvania", "ri" => "rhode island", "sc" => "south carolina", "sd" => "south dakota", "tn" => "tennessee", "tx" => "texas", "ut" => "utah", "vt" => "vermont", "va" => "virginia", "wa" => "washington", "wv" => "west virginia", "wi" => "wisconsin", "wy" => "wyoming" );
and loop...
//loop through state array build state select box foreach( $usstates $key => $value ) { $selected = ""; if($_post['orderstate'] == $key) $selected = "selected"; $wpgft_post_content .= '<option value="'.$key.'" ' . $selected . '>'. $value .'</option>'; } $wpgft_post_content .='</select>'; if($error_state) $wpgft_post_content .='<br /><span class="wpgft_error">'.$error_state.'</span></dd>'; } else { $wpgft_post_content .='<dt>state / province / region:</dt>'; $wpgft_post_content .= '<select name="orderstate"'.$ro.'>';
if need set colorado default state, where/how do this?
$wpgft_post_content .= '<option value="'.$key.'" ' . ($key==='co'?'selected':'') . '>' . $value . '</option>';
Comments
Post a Comment