Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/09/2014, 20:07
Avatar de Fernarey1810
Fernarey1810
 
Fecha de Ingreso: noviembre-2008
Mensajes: 214
Antigüedad: 15 años, 5 meses
Puntos: 1
selectedIndex select dinamico

Probar el siguiente código por favor. La duda es la siguiente. Tengo un array de SELECTS que se van agregando dinamicamente y para tomar todos sus valores desde php necesito pasarlos como arrray.
Si lo uso de esta forma anda (pero esta forma no me sirve):

<select id="1" name="grups" size="1">
document.otro.grups.options[indice].value;

Si lo uso de esta otra forma no anda y esta es la forma que necesito que funcione:
<select id="1" name="grups[1]" size="1">
document.otro.grups[1].options[indice].value;

Como soluciono esto?.

Código Javascript:
Ver original
  1. <html>
  2. <head>
  3. <title></title>
  4. <script>
  5. var counter = 2;
  6. var arreg = [];
  7. var ig = 0;
  8.  
  9. function crear(){
  10.     var cadena = "XS:S:M:L:XL:XXL:XXXL:U:AM";
  11.     var vec = cadena.split(":");
  12.     var conjunto = "<option value='0'>Talles</option>";
  13.                
  14.     for (i = 0; i < (vec.length - 1); i++){    
  15.         var indice = document.otro.grups.selectedIndex;
  16.         var valor = document.otro.grups.options[indice].value;
  17.         arreg[ig] = valor;
  18.         if (vec[i] == arreg[ig]){
  19.             conjunto += "<option selected value=\""+vec[i]+"\">"+vec[i]+"</option>";
  20.             arreg[ig] = vec[i];
  21.         }else
  22.             conjunto+="<option value=\""+vec[i]+"\">"+vec[i]+"</option>";
  23.     }
  24.     ig++;  
  25.     document.getElementById('pp').innerHTML+="<select id=\""+counter+"\" name=\"grups["+counter+"]\" size=\"1\">"+conjunto+"</select><input type='text'  id=\""+counter+"\" name=\"talle["+counter+"]\">";
  26.      
  27.     counter++;
  28. }
  29. </script>
  30. </head>
  31. <body>
  32. <form action="Ej 1.html" method="post" name="otro"  >
  33. <div id="pp">
  34.     <select id="1" name="grups" size="1">
  35.         <option value="0">Talles</option>
  36.         <option value="XS">XS</option>
  37.         <option value="S">S</option>
  38.         <option value="M">M</option>
  39.         <option value="L">L</option>
  40.         <option value="XL">XL</option>
  41.         <option value="XXL">XXL</option>
  42.         <option value="XXXL">XXXL</option>
  43.         <option value="U">U</option>
  44.     </select>
  45.     <input type="text"  id="1" name="talle[1]">
  46. </div><br>
  47. </form>
  48. <br><br><br><a href="javascript:crear()">agregar select</a>
  49. </body>
  50. </html>