Posted By

fuzzylollipop on 02/04/10


Tagged

javascript input dynamic


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

fuzzylollipop


javascript inputbox increment


 / Published in: JavaScript
 

URL: http://forums.digitalpoint.com/showthread.php?t=1057277

  1. <html>
  2. <head>
  3. <style>
  4. .foo {
  5. background: #ccc;
  6. font-weight: bold;
  7. margin: 2px;
  8. }
  9. </style>
  10. </head>
  11. <body>
  12.  
  13. <input id="button" type="button" value="add input" /><br /><br />
  14. <div id="inputs" style="width: 200px;"></div>
  15. <script type="text/javascript">
  16. var target = document.getElementById("inputs"), count = 1, addInput = function() {
  17. var input = document.createElement("input");
  18. input.setAttribute("name", "field"+count);
  19. input.setAttribute("id", "field"+count);
  20. input.setAttribute("value", "field"+count);
  21. input.setAttribute("size", 5);
  22. input.className = "foo";
  23. target.appendChild(input);
  24. count++;
  25. };
  26.  
  27. document.getElementById("button").onclick = addInput;
  28. </script>
  29. </body>
  30. </html>

Report this snippet  

You need to login to post a comment.