2

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 this:

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 too. Just the file-upload won't work.

Any suggestions how that could be done?

Ryan Berger
  • 9,644
  • 6
  • 44
  • 56
janoliver
  • 7,744
  • 14
  • 60
  • 103

1 Answers1

1

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
  • 6,268
  • 29
  • 23