By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,649 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

dynamic file input controls

P: n/a
J.R
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.
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
VK
You cannot set/access file properties from JavaScript : the access is locked
for security reasons.
J.R <so*****@somewhere.com> wrote in message
news:Y7abb.4118$I36.3840@pd7tw3no...
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.

Jul 20 '05 #2

P: n/a
Ivo
"J.R" <so*****@somewhere.com> wrote in message
news:Y7abb.4118$I36.3840@pd7tw3no...
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
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.