Ver Mensaje Individual
  #1 (permalink)  
Antiguo 31/07/2014, 03:19
pilucho
 
Fecha de Ingreso: noviembre-2004
Ubicación: NULL
Mensajes: 652
Antigüedad: 19 años, 5 meses
Puntos: 6
array Valores de numeros por texto

Hola a tods, no tengo idea como funciona el javascript, pero espero me puedan ayudar un poco con esta idea, encontre este codigo y me funciona muy bien, pero necesito que funcione con letras no con numeros es posible? cuando digo numeros me refiero al a: new Array(1,1,"opcion1-1"),

Código HTML:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function cargarSelect2(valor)	{
    var arrayValores=new Array(
        new Array(1,1,"opcion1-1"),
        new Array(1,2,"opcion1-2"),
        new Array(1,3,"opcion1-3"),
        new Array(2,1,"opcion2-1"),
        new Array(3,1,"opcion3-1"),
        new Array(3,2,"opcion3-2"),
        new Array(3,3,"opcion3-3")
    );
    if(valor==0)	{
   // desactivamos el segundo select
    document.getElementById("select2").disabled=true;
    }else{
    // eliminamos todos los posibles valores que contenga el select2
    document.getElementById("select2").options.length=0;
	// añadimos los nuevos valores al select2
    document.getElementById("select2").options[0]=new Option("Selecciona una opcion", "0");
    for(i=0;i<arrayValores.length;i++)	{
            // unicamente añadimos las opciones que pertenecen al id seleccionado
            // del primer select
    if(arrayValores[i][0]==valor)	{
    document.getElementById("select2").options[document.getElementById("select2").options.length]=new Option(arrayValores[i][2], arrayValores[i][1]);
	}	}
    // habilitamos el segundo select
    document.getElementById("select2").disabled=false;
    }	}

function seleccinado_select2(value)		{
    var v1 = document.getElementById("select1");
    var valor1 = v1.options[v1.selectedIndex].value;
    var text1 = v1.options[v1.selectedIndex].text;
    var v2 = document.getElementById("select2");
    var valor2 = v2.options[v2.selectedIndex].value;
    var text2 = v2.options[v2.selectedIndex].text;
}
</script>
</head>

<body>


        <select id='select1' onchange='cargarSelect2(this.value);'>
            <option value='0'>Selecciona una opcion</option>
            <option value='1'>opcion 1</option>
            <option value='2'>opcion 2</option>
            <option value='3'>opcion 3</option>
        </select>

        <select id='select2' onchange='seleccinado_select2();' disabled>
            <option value='0'>Selecciona una opcion</option>
        </select>

</html> 
La idea es algo asi, y disculpen a todos los programadores en javascript si ofende mi ignorancia pero necesito q funcione de esta manera: sera posible??

Código HTML:
<script type="text/javascript">
function cargarSelect2(valor)	{
    var arrayValores=new Array(
        new Array("Gato 1","Abisinio","Gato 1"),
        new Array("Gato 1","Angora","Gato 1"),
        new Array("Gato 1","Belinés","Gato 1"),
        new Array("Perro 2","Afgano","Perro 2"),
        new Array("Perro 2","American Bully","Perro 2"),
        new Array("Ave 3","Paloma","Ave 3"),
        new Array("Ave 3","Condor","Ave 3")
    );
}
</script>
        <select id='select1' onchange='cargarSelect2(this.value);'>
            <option value='Selecciona una opcion'>Selecciona una opcion</option>
            <option value='Gato 1'>Gato 1</option>
            <option value='Perro 2'>Perro 2</option>
            <option value='Ave 3'>Ave 3</option>
        </select>

        <select id='select2' onchange='seleccinado_select2();' disabled>
            <option value='Selecciona una opcion'>Selecciona una opcion</option>
        </select>
restltado:
Primera opcion:
seleccion [Gato 1]

Segunda opcion:
seleccion [Abisinio]
seleccion [Angora]
seleccion [Belinés]