Ver Mensaje Individual
  #4 (permalink)  
Antiguo 25/07/2010, 08:16
Avatar de Adler
Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Ayuda formulario

Hola

Algo como esto
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[]");
  12.     input.setAttribute("id", "campo" + i);
  13.     input.setAttribute("size", "12");
  14.     input.className = "input";
  15.     salto.appendChild(text);
  16.     salto.appendChild(input);
  17.     div.appendChild(salto);
  18.     }
  19. }
  20. </script>
  21.  
  22. </head>
  23. <body>
  24. <form>
  25. ¿Cuantos Campos? <input type="text" name="cantidad" id="cantidad" value="" onkeyup="crearCampos(this.value);" />
  26. <input type="button" id="boton" value="Crear/Eliminar Campos" onclick="crearCampos(this.form.cantidad.value);" />
  27. <div id="campos_dinamicos"></div>
  28. </form>
  29. </body>
  30. </html>

PD: Aunque sería más sencillo con cloneNode()

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

Última edición por Adler; 25/07/2010 a las 08:24 Razón: algo de info