Jump to content
Fórum Script Brasil
  • 0

Select


fantasma
 Share

Question

como fazer isto funcionar

<html><head><title>Teste JavaScript</title>

&lt;script language="javascript">

function definir_opcao2 (opcao1){
if (opcao1.value=="Carros") {
opcao2.options[0].value = "Ford"
opcao2.options[1].value = "Fiat"
opcao2.options[2].value = "Volks"
}
else {
if (opcao1.value = "Países") {
opcao2.options[0].value = "Brasil"
opcao2.options[1].value = "Japão"
opcao2.options[2].value = "EUA"
}

else {
opcao2.options[0].value = "Azul"
opcao2.options[1].value = "Verde"
opcao2.options[2].value = "Preto"
}
}
}

</script>
</head>
<body>

<form>
<select name="opcao1" size="1" onchange="definir_opcao2(opcao1.options[selectedindex].value)">
<option>Carros</option>
<option>Países</option>
<option>Cores</option>
</select>

<select name="opcao2" size="1">
<option>Ford</option>
<option>Fiat</option>
<option>Volks</option>
</select>
</form>

</body></html>

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Montei aqui outra opcao... quem quiser melhorar/criticar fiquem a vontade rssss

<script language="javascript">
function PopulaCombo(id_tipo)
{
var ArrayTipo;

if (id_tipo == 1)
	ArrayTipo = new Array ("Violeta","Azul","Vermelho","Branco");
else if (id_tipo == 2)
	ArrayTipo = new Array ("Amora","Morango","Abacaxi");
else if (id_tipo == 3)
	ArrayTipo = new Array ("São Paulo","Curitiba","Palmas","Pernambuco");

document.form.opcao.disabled = false;
document.form.opcao.options.length = 0;
for (i=0; i <= ArrayTipo.length-1; i++){
  window.document.form.opcao.options[i] = new Option(ArrayTipo[i],i);
}
}

</script>

<form name="form">

<table border="0" width="310">
	<tr>
		<td width="150"><select name="tipo" onchange="PopulaCombo(this.value)">
										<option value="">Selecione</option>
										<option value="1">Cor</option>
										<option value="2">Fruta</option>
										<option value="3">Cidade</option>
										</select>
		</td>
		<td width="160"><select name="opcao" disabled>
										</select>
		</td>
	</tr>
</table>
</form>

Link to comment
Share on other sites

  • 0

Isso já deve resolver:

&lt;script language="javascript">
function PopulaCombo(id_tipo)
{
var ArrayTipo;

if (id_tipo == 1)
	ArrayTipo = new Array ("Violeta","Azul","Vermelho","Branco");
else if (id_tipo == 2)
	ArrayTipo = new Array ("Amora","Morango","Abacaxi");
else if (id_tipo == 3)
	ArrayTipo = new Array ("São Paulo","Curitiba","Palmas","Pernambuco","Fortaleza","Rio de Janeiro","Belo Horizonte");
else
{
for (i=document.form.opcao.options.length -1; i>= 0 ; i--)
{
document.form.opcao.options.remove(i);
}
document.form.opcao.disabled = true;
return;
}

document.form.opcao.disabled = false;
document.form.opcao.options.length = 0;
for (i=0; i <= ArrayTipo.length-1; i++){
  window.document.form.opcao.options[i] = new Option(ArrayTipo[i],i);
}
}

</script>

Link to comment
Share on other sites

  • 0

Ok obrigado, preciso estudar mais javascript...hahahahahahaha

mas uma duvida

no lugar de Violeta","Azul","Vermelho","Branco..................tem como por u "select * from"

Edited by fantasma
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      151k
    • Total Posts
      649.1k
×
×
  • Create New...