I am building a web form where there is a list of inputs. So far, so good.
However, how can I add a link/button to add say another 5 fields to the list. eg:
<input>
<input>
<input>
<input>
<a href="" onclick="">Add 10 more fields</a>
I have looked through many similar q's on this site, however none seem to describe how to add multiple fields.
Thanks for any help,
Harley
EDIT: Thanks all for help, looks like jquery append is the way to go. However I appreciate the alternative that does not use jquery.
Yep, jquery is the way to go here.
Good luck.
try use the JQuery .append() function
While you already have answers, I thought I'd try and provide a non-jQuery solution:
JS Fiddle demo.
I don't have IE to test, but the above should work with IE < 9 using the
attachEvent
fall-back, and >= 9, I think, implements the standardaddEventListener()
.References:
addEventListener()
.attachEvent()
.document.createElement()
.insertBefore()
.....
The following example add input box at click a link:
Here's a js fiddle showing the example of adding 10 inputs using jQuery's append() function. I suggest only doing one addition per click as in user1301840's example though.
HTML
Javascript