Ver Mensaje Individual
  #3 (permalink)  
Antiguo 17/03/2010, 08:38
Avatar de Adler
Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 2 meses
Puntos: 126
Respuesta: Crear nuevos textbox segun opción elegida de un select

Hola

Prueba este otro script que a efectos prácticos es lo mismo

Código Javascript:
Ver original
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function crearCampos(cantidad){
  5. var div = document.getElementById("campos_dinamicos");
  6. while(div.firstChild)div.removeChild(div.firstChild); // remover elementos;
  7.     for(var i = 1, cantidad = Number(cantidad); i <= cantidad; i++){
  8.     var salto = document.createElement("P");
  9.     var input = document.createElement("input");
  10.     var text = document.createTextNode("Campo Dinamico " + i + ": ");
  11.     input.setAttribute("name", "campo" + i);
  12.     input.setAttribute("size", "12");
  13.     input.className = "input";
  14.     salto.appendChild(text);
  15.     salto.appendChild(input);
  16.     div.appendChild(salto);
  17.     }
  18. }
  19. </script>
  20.  
  21. </head>
  22. <body>
  23. <form>
  24. ¿Cuantos Campos? <input type="text" name="cantidad" id="cantidad" value="" onkeyup="crearCampos(this.value);" />
  25. <input type="button" id="boton" value="Crear/Eliminar Campos" onclick="crearCampos(this.form.cantidad.value);" />
  26. <div id="campos_dinamicos"></div>
  27. </form>
  28. </body>
  29. </html>

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;" />