"J.R" <someone (AT) somewhere (DOT) com> wrote
Quote:
Greetings,
I'm adding dynamically created input type='file' controls via JavaScript.
However when I try to access they do not seem to be returned in the form
collection. Any ideas?
Thanks, John. |
Are you sure they have unique names, or if not, unique indeces in an array?
Here is what I use, more or less directly copied from the page so it is not
tailored to the question:
<script type=text/javascript>
function add(n){
curdiv=document.activeElement.previousSibling;
newdiv=curdiv.cloneNode(true);
curdiv.insertAdjacentElement("afterEnd",newdiv);
}
</script>
<form method=post enctype="multipart/form-data" action="/script.htm">
<input type=hidden name=MAX_FILE_SIZE value=3000000>
<div>File: <input type=file name=userfile[]></div>
<input class=button type=button value="Add" onclick=add(this) ><br>
<input class=button type=submit value=" Upload ">
</form>
There are several forms on this page, each with their own "Add" button, and
in the case of the upload form with the <input type=file>,
activeElement.previousSibling (not sure if this is IE only) is the div
containing both the input and its label. Note the input name is a member of
an array because of the square brackets. This ensures the server script that
receives the form submission will see all inputs, regardless of how many
times I clicked "Add"!
HTH
Ivo