Ticket #11981 (closed bug: invalid)
Form create Dinamicaly
| Reported by: | soares_289@… | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | unfiled | Version: | 1.7.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
When creating a form via jquery and use the method submit, a new window is open in Chrome and the submit go to the wrong place. In Safari and FireFox the submit don`t send.
The code used:
var form = $("<form method=\"post\" enctype=\"multipart/form-data\" name=\"uploadFile\" target=\"index.php\"></form>");
var file = $("<input type=\"file\" name=\"file1\" id=\"upload\" />");
$(form).append( file );
file.change(function(){
$("#save").click();
$(form).submit();
});
file.click();
I solve the problem with this:
var form = document.createElement("form");
var file = $("<input type=\"file\" name=\"file1\" id=\"upload\" />");
$(form).attr("method","post");
$(form).attr("action","index.php");
$(form).attr("enctype","multipart/form-data");
$(form).append( file );
file.change(function(){
$(form).submit();
});
file.click();
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

You have to use the action-attribut, not the target-attribut.
In the second example you're doing it, right, in the first it is wrong.