Ver Mensaje Individual
  #4 (permalink)  
Antiguo 05/04/2009, 07:40
Avatar de Adler
Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 18 años, 2 meses
Puntos: 126
Respuesta: Listas dependientes

Hola

Mas sencillo, por el maestro Javier_B. Solo necesitaba una pequeña modificación

Código javascript:
Ver original
  1. <style type="text/css">
  2. select {width:80px}
  3. </style>
  4. <script type="text/javascript">
  5. <!--
  6. function pasar1() {
  7.     obj=document.getElementById('sel1');
  8.     if (obj.selectedIndex==-1) return;
  9.   for (i=0; opt=obj.options[i]; i++)
  10.     if (opt.selected) {
  11.         valor=opt.value; // almacenar value
  12.         txt=obj.options[i].text; // almacenar el texto
  13.         obj.options[i]=null; // borrar el item si está seleccionado
  14.         obj2=document.getElementById('sel2');
  15.     opc = new Option(txt,valor);
  16.         eval(obj2.options[obj2.options.length]=opc);   
  17.   }
  18. }
  19.  
  20.  
  21.  
  22. function pasar2() {
  23.     obj=document.getElementById('sel2');
  24.     if (obj.selectedIndex==-1) return;
  25.   for (i=0; opt=obj.options[i]; i++)
  26.     if (opt.selected) {
  27.         valor=opt.value; // almacenar value
  28.         txt=obj.options[i].text; // almacenar el texto
  29.         obj.options[i]=null; // borrar el item si está seleccionado
  30.         obj2=document.getElementById('sel1');
  31.         opc = new Option(txt,valor);
  32.         eval(obj2.options[obj2.options.length]=opc);
  33.   }
  34. }
  35. -->
  36. </script>
  37. </head>
  38.  
  39. <body>
  40. <p>
  41. <label for="sel1">Origen:</label>
  42. <select id="sel1" size="5" multiple="multiple">
  43. <option value="1">Uno</option>
  44. <option value="2">Dos</option>
  45. <option value="3">Tres</option>
  46. <option value="4">Cuatro</option>
  47. <option value="5">Cinco</option>
  48. </select>
  49. <label for="sel2">Destino:</label>
  50. <select id="sel2" size="5">
  51. </select></p>
  52. <input type="button" value="Pasar >>" onclick="pasar1()" />
  53. <input type="button" value="<< Pasar" onclick="pasar2()" />

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />