tags:

views:

67

answers:

2

Hey there,

I have a simple field somewhere in my document. Now I want to CREATE a form with jQuery, add this input field to it and submit it via Javascript.

Something like that:

var newform = $( document.createElement('form') );
newform.attr("method","post")
       .attr("action",action)
       .attr("enctype","multipart/form-data");
       .append($("#file").clone())
       .submit();

Unfortunately, $_FILES gives me error code 4: "No file submitted". I tried this with simple Text fields, and it worked for them, their value has been submitted to! Just the file-upload won't work.

Any suggestions how that could be done?

Regards, Jan Oliver

+1  A: 

That's pretty much the same problem I'm experiencing:

http://stackoverflow.com/questions/415483/clone-a-file-input-element-in-javascript

janoliver
A: 

I think it has to do with the fact that $("#file").clone() would cause the input appended to the form to have the same id '#file'.

czarchaic