/ Published in: PHP

para marcar um estado como selecionado:
comboEstados(SP);
comboEstados(SP);
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function comboEstados($marcado = false){ $montarArray = array("AC", "AL", "AM", "AP", "BA", "CE", "DF", "ES", "GO", "MA", "MG", "MS", "MT", "PA", "PB", "PE", "PI", "PR", "RJ", "RN", "RO", "RR", "RS", "SC", "SE", "SP", "TO"); if ($marcado == ""){ foreach($montarArray as $i){ $resultArray .= "<option value=\"{$i}\">{$i}</option>"; } return $resultArray; }else{ foreach ($montarArray as $i){ if ($marcado == $i){ $resultArray .= "<option value=\"{$i}\" selected=\"selected\">{$i}</option>"; }else{ $resultArray .= "<option value=\"{$i}\">{$i}</option>"; } } return $resultArray; } }
Comments
