HighDots Forums  

dynamic file input controls

Javascript JavaScript language (comp.lang.javascript)


Discuss dynamic file input controls in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
J.R
 
Posts: n/a

Default dynamic file input controls - 09-20-2003 , 11:52 PM






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.



Reply With Quote
  #2  
Old   
VK
 
Posts: n/a

Default Re: dynamic file input controls - 09-21-2003 , 04:01 AM






You cannot set/access file properties from JavaScript : the access is locked
for security reasons.


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.





Reply With Quote
  #3  
Old   
Ivo
 
Posts: n/a

Default Re: dynamic file input controls - 09-21-2003 , 04:17 AM



"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




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.