Dynamically generated file upload form in IE

E

eniacpx

I have a form being generated from scratch using the appendChild and
createElement methods. In this form there is a file input field. If the
form is submitted in FF it works like a charm, but in IE it just passes
the filename to my handler script, any ideas? I need this functionality
to get around POST data size limits, this is for an image gallery, so I
want people to be able to upload multiple files, the solution I have
found is to generate multiple forms, and submit them one at a time,
which again, works seamlessly in FF. I have included some code below:

function addFileNew(id){
baseNum = id.replace(/(\D)/g,'');
nextNum = parseInt(baseNum)+1;
alert(nextNum);
baseName = id.replace(/(\d)/g,'');
x = getObj(id);

parentID = x.parentNode;
newForm = document.createElement("form");
fName = baseName + nextNum;
newForm.setAttribute("name",fName);
newForm.setAttribute("id",fName);
newForm.setAttribute("method","POST");
newForm.setAttribute("action","uphandler.php");
newForm.setAttribute("enctype","multipart/form-data");
newForm.setAttribute("target","fTarget");

formname = document.createElement("input");
formname.setAttribute("type","hidden");
formname.setAttribute("name","formname");
formname.setAttribute("value",baseName);

formnum = document.createElement("input");
formnum.setAttribute("type","hidden");
formnum.setAttribute("name","formnum");
formnum.setAttribute("value",nextNum);

formAlbum = document.createElement("input");
formAlbum.setAttribute("type","hidden");
formAlbum.setAttribute("name","album");
formAlbum.setAttribute("value",document.fileInput0.album.value);

formNewAlbum = document.createElement("input");
formNewAlbum.setAttribute("type","hidden");
formNewAlbum.setAttribute("name","newAlbum");
formNewAlbum.setAttribute("value",document.fileInput0.newAlbum.value);

formAccess = document.createElement("input");
formAccess.setAttribute("type","hidden");
formAccess.setAttribute("name","access");
if(document.fileInput0.access.checked){
access = "on";
} else {
access = "off";
}
formAccess.setAttribute("value",access);

formIn = document.createElement("input");
formIn.setAttribute("name","uploadedfiles[]");
formIn.setAttribute("type","file");
fId = "file" + nextNum;
dId = "del" + nextNum;
formIn.setAttribute("id",fId);
if(formIn.attachEvent)
{
//Do IE Specific
formIn.attachEvent("onchange", new Function("addFileNew('" + fName +
"'); changeClass('" + dId + "','visible');"));
} else {
formIn.setAttribute("onChange","addFileNew('" + fName +
"');changeClass('" + dId + "','visible');");
}

delButton = document.createElement("input");
delButton.setAttribute("type","button");
delButton.setAttribute("value","Delete");
delButton.setAttribute("name","delButton");
delButton.className = "hidden";
delButton.setAttribute("id",dId);

if(delButton.attachEvent)
{
//Do IE Specific
delButton.attachEvent("onclick", new Function("deleteElement('" +
fName + "');"));
} else {
delButton.setAttribute("onClick","deleteElement('" + fName + "');");
}

newForm.appendChild(formIn);
newForm.appendChild(formname);
newForm.appendChild(formnum);
newForm.appendChild(formAlbum);
newForm.appendChild(formNewAlbum);
newForm.appendChild(formAccess);
newForm.appendChild(delButton);
parentID.insertBefore(newForm,x);


}
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top