Ver Mensaje Individual
  #11 (permalink)  
Antiguo 22/11/2011, 10:17
Avatar de Kaopectate
Kaopectate
Colaborador
 
Fecha de Ingreso: diciembre-2001
Ubicación: Curaçao (Antillas Holandesas)
Mensajes: 3.179
Antigüedad: 24 años, 9 meses
Puntos: 38
Respuesta: Selects dependientes

Eso es lo que creí haber hecho, solo que usando nómeros. Míralo con nombres:

Código PHP:
<html>
 <
head>
  <
script language='JavaScript'>

   var 
    
aNumeros = new Array('Enrique', 'Iván', 'Felipe', 'Camilo', 'Ernesto', 'Julio', 'Javier', 'Hernán');
    
aValores = new Array('Felipe', 'Julio', 'Javier', 'Iván');

   function 
addOption(oCntrl, iPos, sTxt, sVal){
    var 
oOption = new Option(sTxt, sVal);
    
oCntrl.options[iPos] = oOption;
   }

   function 
esValido(iControl, nVal){
    var 
bRes = true;
    for (var 
i = 0; i < aValores.length; i++)
     if (
i != iControl)
      
bRes = bRes && (aValores[i] != nVal);
    return 
bRes;
   }

   function 
preasigna(){
    for (var 
i = 1; i <= 4; i++){
     
oSel = document.getElementById('s' + i);
     while (
oSel.length)
      
oSel.remove(0);
     for (var 
j = 0, p = 0; j < aNumeros.length; j++){
      if (
esValido(i - 1, aNumeros[j]))
       
addOption(oSel, p++, aNumeros[j], aNumeros[j]); 
     }
     
oSel.value = aValores[i - 1];
    }
   }

   function 
recalcula(oSel, nSel){
    
aValores[nSel - 1] = oSel.value;
    
preasigna();
   }

   function 
muestra(){
    
alert('s1=' + document.getElementById('s1').value + ' s2=' + document.getElementById('s2').value + ' s3=' + document.getElementById('s3').value + ' s4=' + document.getElementById('s4').value);
   }

  
</script>
 </head>
 <body>
  <select id='s1' onchange='recalcula(this, 1)'></select>
  <select id='s2' onchange='recalcula(this, 2)'></select>
  <select id='s3' onchange='recalcula(this, 3)'></select>
  <select id='s4' onchange='recalcula(this, 4)'></select>
  <input type='button' value='show' onclick='muestra()'>
  <script language='JavaScript'>

   preasigna();

  </script>
 </body>
</html>