Ir para conteúdo
Fórum Script Brasil
  • 0

Formulário Com Carregamento Da 'cidade'


Guest - Flávio -

Pergunta

Guest - Flávio -

Olá pessoal,onde eu encontro o script de formulário que carrega automáticamente as 'cidades' de um determinado 'estado' escolhido previamente,tipo assim;eu escolho o estado de São Paulo e automáticamente aprece no campo abaixo a relação de todas as cidades de São Paulo para no caso o usuário escolher qual a cidade de sua preferência.

Obrigado pela atenção.

Link para o comentário
Compartilhar em outros sites

3 respostass a esta questão

Posts Recomendados

  • 0

cara, a lógica é essa:

você vai fazer uma matriz bidimensional e cada estado vai ser uma linha e as cidades vao ser as colunas. Vou postar um exemplo garimpado da net para ilustrar.

<script language="javascript">
function somethingselected(oList){
  var curform = oList.form; // get the containing form
  clearCombobox(curform.list2); // clear the downstream list
  var newvalue = oList.name + "=" + oList.options[oList.selectedIndex].value;
  fillCombobox(curform.list2, newvalue); // fill the downstream list
}
</script>
<script language="javascript"><!--
function comboItemSelected(oList1,oList2){
if (oList2!=null){
clearComboOrList(oList2);
if (oList1.selectedIndex == -1){
oList2.options[oList2.options.length] = new Option('Please make a selection from the list', '');
} else {
fillCombobox(oList2, oList1.name + '=' + oList1.options[oList1.selectedIndex].value);
}
}
}
function listboxItemSelected(oList1,oList2){
if (oList2!=null){
clearComboOrList(oList2);
if (oList1.selectedIndex == -1){
oList2.options[oList2.options.length] = new Option('Please make a selection from the list', '');
} else {
fillListbox(oList2, oList1.name + '=' + oList1.options[oList1.selectedIndex].value);
}
}
}
function clearComboOrList(oList){
for (var i = oList.options.length - 1; i >= 0; i--){
oList.options[i] = null;
}
oList.selectedIndex = -1;
if (oList.onchange)	oList.onchange();
}
function fillCombobox(oList, vValue){
if (vValue != '') {
if (assocArray[vValue]){
oList.options[0] = new Option('Please make a selection', '');
var arrX = assocArray[vValue];
for (var i = 0; i < arrX.length; i = i + 2){
if (arrX[i] != 'EOF') oList.options[oList.options.length] = new Option(arrX[i + 1], arrX[i]);
}
if (oList.options.length == 1){
oList.selectedIndex=0;
if (oList.onchange) oList.onchange();
}
} else {
oList.options[0] = new Option('None found', '');
}
}
}
function fillListbox(oList, vValue){
if (vValue != '') {
if (assocArray[vValue]){
var arrX = assocArray[vValue];
for (var i = 0; i < arrX.length; i = i + 2){
if (arrX[i] != 'EOF') oList.options[oList.options.length] = new Option(arrX[i + 1], arrX[i]);
}
if (oList.options.length == 1){
oList.selectedIndex=0;
if (oList.onchange)	oList.onchange();
}
} else {
oList.options[0] = new Option('None found', '');
}
}
}
//--></script>




  <body>
    <form name="lala" action="">
<select name='list1' size='1' style='width:200;' onchange='comboItemSelected(this,this.form.list2);'>
<option>Please make a selection</option>
<option value="1389">Algodata Infosystems</option>
<option value="0877">Binnet & Hardley</option>
<option value="1622">Five Lakes Publishing</option>
<option value="9901">GGG&G</option>
<option value="9999">Lucerne Publishing</option>
<option value="0736">New Moon Books</option>
<option value="1756">Ramona Publishers</option>
<option value="9952">Scootney Books</option>
</select>
<select name='list2' size='1' style='width:360;'>
    <option>Please select something from the first list</option>
<script language='javascript'>

if (!assocArray) var assocArray = new Object();
assocArray["list1=0736"] = new Array(
    "PS7777","Emotional Security: A New Algorithm",
    "PS2091","Is Anger the Enemy?",
    "PS2106","Life Without Fear",
    "PS3333","Prolonged Data Deprivation: Four Case Studies",
    "BU2075","You Can Combat Computer Stress!",
    "EOF");
assocArray["list1=0877"] = new Array(
    "PS1372","Computer Phobic AND Non-Phobic Individuals: Behavior Variations",
    "TC4203","Fifty Years in Buckingham Palace Kitchens",
    "TC3218","Onions, Leeks, and Garlic: Cooking Secrets of the Mediterranean",
    "MC2222","Silicon Valley Gastronomic Treats",
    "TC7777","Sushi, Anyone?",
    "MC3021","The Gourmet Microwave",
    "MC3026","The Psychology of Computer Cooking",
    "EOF");
assocArray["list1=1389"] = new Array(
    "PC1035","But Is It User Friendly?",
    "BU1111","Cooking with Computers: Surreptitious Balance Sheets",
    "PC9999","Net Etiquette",
    "PC8888","Secrets of Silicon Valley",
    "BU7832","Straight Talk About Computers",
    "BU1032","The Busy Executive's Database Guide",
    "EOF");
</script>
</select>
</form>

tah aí o bixo. Vai do seu talento alterar e tornar dinâmico (mas se precisar de ajuda é só falar porque já fiz isso hehhe)

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...