Adding form fields dynamicly

E

emperor-laban

How can I add more <input type="file" /> -fields by the click of a
button? The idea is that the clients should be able to upload a number
of files from the same form, but I shouldn't need to know how many
fields they need to begin with. Would be good to have an option to
remove fields as well.
 
M

Martin Honnen

How can I add more <input type="file" /> -fields by the click of a
button? The idea is that the clients should be able to upload a number
of files from the same form, but I shouldn't need to know how many
fields they need to begin with. Would be good to have an option to
remove fields as well.

You can create elements with the factory method createElement of the
document and then insert it as needed in your document with e.g.
appendChild called on the element you want to insert the input it, for
instance the form element object or one of its descendants:
var input;
if (document.createElement && (input =
document.createElement('input'))) {
input.type = 'file';
input.name = 'file1';
input.id = 'file1';
form.appendChild(input);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top