nelson
Alguém aí manja de JavaScript?
11 de December de 2001 às 06:45PM


Oi Pessoal,
Alguém manja de javascript por aí?


O script está funcionando +/- do jeito que eu preciso, mas são três combos, a primeira está ok, já a segunda, mostra as opções corretas no terceiro combo, mas quando eu altero as seleções nesta combo2, vai sumindo a opção anterior até esvaziar a combo.



<!-- TWO STEPS TO INSTALL COUNTRY CHOOSER:

1. Paste the first code in the HEAD of your HTML document
2. Add the last coding to the BODY of your HTML document -->

<!-- STEP ONE: Paste the first code in the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
var CARRO_USADOArray = new Array("('Selecione','',true,true)",
"('VOLKSWAGEN')",
"('FIAT')",
"('FORD')",
"('CHEVROLET')");
var CARRO_NOVOArray = new Array("('Selecione','',true,true)",
"('VOLKSWAGEN')",
"('FIAT')",
"('FORD')",
"('CHEVROLET')");
var MOTO_USADAArray = new Array("('Selecione','',true,true)",
"('HONDA')",
"('YAMAHA')",
"('CAGIVA')",
"('TENERE')");

var MOTO_NOVAArray = new Array("('Selecione','',true,true)",
"('HONDA')",
"('YAMAHA')",
"('CAGIVA')",
"('TENERE')");




var VOLKSWAGENArrai = new Array("('Selecione','',true,true)",
"('GOL')",
"('POLO')",
"('GOLF')",
"('VOYAGE')");


var FIATArrai = new Array("('Selecione','',true,true)",
"('UNO')",
"('PALIO')",
"('MAREA')",
"('TIPO')");



var FORDArrai = new Array("('Selecione','',true,true)",
"('ESCORT')",
"('KA')",
"('FIESTA')",
"('MONDEO')");

var CHEVROLETArrai = new Array("('Selecione','',true,true)",
"('CORSA')",
"('VECTRA')",
"('CELTA')",
"('SEI LÁ')");






<!-- Preenche o COMBO MARCA de acordo com o TIPO -->
function populateMarca(inForm,selected) {
var selectedArray = eval(selected + "Array");
while (selectedArray.length < inForm.marca.options.length) {
inForm.marca.options[(inForm.marca.options.length - 1)] = null;
}
for (var i=0; i < selectedArray.length; i++) {
eval("inForm.marca.options[i]=" + "new Option" + selectedArray[i]);
}
if (inForm.tipo.options[0].value == '') {
inForm.tipo.options[0]= null;
if ( navigator.appName == 'Netscape') {
if (parseInt(navigator.appVersion) < 4) {
window.history.go(0);
}
else {
if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {
window.history.go(0);
}
}
}
}
}

<!-- Preenche o COMBO MODELO de acordo com a MARCA -->


function populateModelo(inForm,selected) {
var selectedArray = eval(selected + "Arrai");
while (selectedArray.length < inForm.modelo.options.length) {

inForm.modelo.options[(inForm.modelo.options.length - 1)] = null;
}
for (var i=0; i < selectedArray.length; i++) {
eval("inForm.modelo.options[i]=" + "new Option" + selectedArray[i]);
}
if (inForm.marca.options[0].value == '') {
inForm.marca.options[0]= null;
if ( navigator.appName == 'Netscape') {
if (parseInt(navigator.appVersion) < 4) {
window.history.go(0);
}
else {
if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {
window.history.go(0);
}
}
}
}
}


// End -->
</script>

<!-- STEP TWO: Add the last coding to the BODY of your HTML document -->



<BODY>

<center>
<form name="globe">

<select name="tipo" onChange="populateMarca(document.globe,document.globe.tipo.options[document.globe.tipo.selectedIndex].value)">
<option selected value=''>Selecione</option>
<option value='CARRO_USADO'>Carro Usado</option>
<option value='CARRO_NOVO'>Carro Novo</option>
<option value='MOTO_USADA'>Moto Usada</option>
<option value='MOTO_NOVA'>Moto Nova</option>
</select>

<select name="marca" onChange="populateModelo(document.globe,document.globe.marca.options[document.globe.marca.selectedIndex].text)">
<option value=''><--------------------</option>
</select>

<select name="modelo" >
<option value=''><--------------------</option>
</select>


</form>
</center>



---------------------------------
Se puder dê uma força.

Abraço

-Nelson
Você precisa estar logado no PHPBrasil.com para poder enviar mensagens para os nossos fóruns.

Faça o login aqui.