Dynamic Form input type="file"
Posted on 2008-06-25
This code, as the body of an HTML document, uploads the user selected file as expected:
<iframe src="/scripts/blank.html" name="backFrame" id="backFrame"></iframe>
<form method="POST" id="postForm" action="/cgi-bin/upload" enctype="multipart/form-data" target="backFrame">
<input type="file" id="inptfle" name="inptfle" class="bttn impbttn1">
<input type="submit" id="subbttn" class="bttn impbttn2" value="Import">
All well & good, but when I try to add these elements dynamically IE v6 doesn't send the full file information, just the name as if it was a standard parameter - I have checked this with a network sniffer and confirmed that this is the case.
I can simulate this scenario by removing the 'name' property from the 'file' element in the plain HTML document and suspect that this may be related to the problem but I have checked (using IE Developer Toolbar) and the name does appear to be the present.
Any ideas would be welcome - a simple snippet that is known to work under IE v6 and dynamically creates a form with just a single input/file element would be a start.
I have tried numerous options including creating the element using both document.createElement and formobject.innerHTML but nothing has worked. The code that works well under Safari (OS X) but always fails under IE v6 (W XP).