Ver Mensaje Individual
  #3 (permalink)  
Antiguo 01/05/2007, 14:32
Avatar de derkenuke
derkenuke
Colaborador
 
Fecha de Ingreso: octubre-2003
Ubicación: self.location.href
Mensajes: 2.665
Antigüedad: 20 años, 6 meses
Puntos: 45
Re: SELECTS dependientes con inteligencia hacia atrás

eh! pues pensaba que funcionaba bien! si básicamente yo pruebo los script en firefox antes que en IE!

Ojo que tampoco funciona simplemente esto:
Código PHP:
<script>

/****************************************************************
    ESTRUCTURA BÁSICA
****************************************************************/
var paises=["PAIS1","PAIS2","PAIS3"];
var 
provincias=[
    [
"PROVINCIA1 (p1)","PROVINCIA2 (p1)",  "PROVINCIA3 (p1)""PROVINCIA4 (p1)"], 
    [
"PROVINCIA1 (p2)""PROVINCIA2 (p2)""PROVINCIA3 (p2)""PROVINCIA4 (p2)""PROVINCIA5 (p2)""PROVINCIA6 (p2)"], 
    [
"PROVINCIA1 (p3)""PROVINCIA2 (p3)""PROVINCIA3 (p3)" ]
];
var 
ciudades=[
    [
        [
"ciud1-1-1""ciud1-1-2""ciud1-1-3""ciud1-1-4""ciud1-1-5" ],
        [
"ciud1-2-1""ciud1-2-2""ciud1-2-3""ciud1-2-4" ],
        [
"ciud1-3-1""ciud1-3-2""ciud1-3-3""ciud1-3-4" ],
        [
"ciud1-4-1""ciud1-4-2""ciud1-4-3" ]
    ],
    
    [
        [
"ciud2-1-1""ciud2-1-2""ciud2-1-3""ciud2-1-4""ciud2-1-5""ciud2-1-6""ciud2-1-7""ciud2-1-8" ],
        [
"ciud2-2-1""ciud2-2-2""ciud2-2-3""ciud2-2-4""ciud2-2-5""ciud2-2-6" ],
        [
"ciud2-3-1""ciud2-3-2""ciud2-3-3""ciud2-3-4""ciud2-3-5""ciud2-3-6" ],
        [
"ciud2-4-1""ciud2-4-2""ciud2-4-3""ciud2-4-4""ciud2-4-5""ciud2-4-6""ciud2-4-7" ],
        [
"ciud2-5-1""ciud2-5-2""ciud2-5-3""ciud2-5-4""ciud2-5-5" ],
        [
"ciud2-6-1""ciud2-6-2""ciud2-6-3""ciud2-6-4""ciud2-6-5" ]
    ],
    
    [
        [
"ciud3-1-1""ciud3-1-2""ciud3-1-3""ciud3-1-4""ciud3-1-5""ciud3-1-6""ciud3-1-7""ciud3-1-8" ],
        [
"ciud3-2-1""ciud3-2-2""ciud3-2-3" ],
        [
"ciud3-3-1""ciud3-3-2""ciud3-3-3""ciud3-3-4" ]
    ]
];


/****************************************************************
    FUNCIONES ÚTILES PARA ARRAYS Y SELECTS
****************************************************************/

//agrega un option a un select, con un par de atributos extra que nos serán útiles
function agregarOpt(elSel,txt,valor,suPais,suProvincia,contieneProvincias,contieneCiudades) {
    var 
indice=elSel.options.length;
    
elSel.optionsindice ] = new Option(txt,valor);
    
elSel.optionsindice ].suPais=suPais;
    
elSel.optionsindice ].suProvincia=suProvincia;
    
elSel.optionsindice ].contieneProvincias=contieneProvincias;
    
elSel.optionsindice ].contieneCiudades=contieneCiudades;
}


/****************************************************************
    CREACIÓN Y RELLENADO DE LOS SELECTS
****************************************************************/

//Creamos los SELECTS
var selPais=document.createElement("SELECT");
var 
selProv=document.createElement("SELECT");
var 
selCiud=document.createElement("SELECT");

//la función coloca en los selects creados todos los valores de los arrays, pudiendo salvar el select que se indique en los argumentos
function reiniciar_selects(conPaises,conProvincias,ConCiudades) {
    
//eliminamos las option de los selects que procedan
    
while( (conPaises==undefined || conPaises) && selPais.options.length>)
        
selPais.options[0]=null;
    while( (
conProvincias==undefined || conProvincias) && selProv.options.length>)
        
selProv.options[0]=null;
    while( (
ConCiudades==undefined || ConCiudades) && selCiud.options.length>)
        
selCiud.options[0]=null;
    
//colocamos las opciones nuevas si procede
    
for(var i=0i<paises.lengthi++) {
        if(
conPaises==undefined || conPaises 
            
agregarOpt(selPaispaises[i], paises[i], nullnullprovincias[i].toString().split(","), ciudades[i].toString().split(",") );
        for(var 
j=0j<provincias[i].lengthj++) {
            if(
conProvincias==undefined || conProvincias )  
                
agregarOpt(selProvprovincias[i][j], provincias[i][j], inullnullciudades[i][j].toString().split(",") );
            for(
k=0k<ciudades[i][j].lengthk++) {
                if(
ConCiudades==undefined || ConCiudades ) {
                    
//cuenta regresiva para contar todas las provincias anteriores (cuantas provincias habia en los paises anteriores)
                    
var aux=i-1provinciasAnteriores=0;
                    while(
aux>=0)
                        
provinciasAnteriores+=provincias[aux--].length;
                    
agregarOpt(selCiudciudades[i][j][k], ciudades[i][j][k], iprovinciasAnteriores+jnullnull);
                }
            }
        }
    }
}

reiniciar_selects(true,true,true);        //todos los valores en todos los selects

//adjuntamos al documento
document.body.appendChild(selPais);
document.body.appendChild(selProv);
document.body.appendChild(selCiud);




//creamos un botón por si acaso se necesita restablecer todo:
var boton=document.createElement("INPUT");
with(boton) {
    
type="button"value="Restablecer"onclick=reiniciar_selects;
}
document.body.appendChild(boton);


</script> 
¿Por qué podrá ser?
__________________
- Haz preguntas inteligentes, y obtendrás más y mejores respuestas.
- Antes de postearlo Inténtalo y Búscalo.
- Escribe correctamente tus mensajes.