I have an upload form that is working fine with a submit button, but I really would like it to submit on its own without a submit button onChange when a user selects an image. I have it sending the form with onChange but it is not sending the uploaded file like when you hit the button! It is sending it as “example.jpg” instead of actually sending the file for upload.
Does anyone know what could possibly be wrong? Is there something special you need to add?
Thanks a lot!
Do you use <input type=“file”>? Can you post here the minimalistic sample that demonstrates the issue or provide the URL?
@jreider: you are right and the value of the input[@type=‘file’] cannot be changed by the page. But it triggers onchange when user changes its value by typing in it or by browsing for file so the form can be submittedby attaching submit code to this event. I believe that mail.google.com handles attachments in that way.
What do you think a work around would be? I’ve honestly been at this all of yesterday with no luck lol.
I’m using <input type=“file” name=“image” onChange=“submit()”>
The JS is simply:
For how frustrating this has been, I’m surprised that there is not anything on the subject on Google. I cannot find anyone having trouble with submitting a form with java and keeping file uploads intact. Do you have any idea where to go from here?
If you want to perform file uploads via ajax, it requires submitting the form from an iframe so that only the iframe reloads, and not the rest of the page.
The upload page is located within an iframe already on the post page. So you’re saying that if I have it submit to an iframe from the top level page it will work?
This works fine for me with opera9, ff3, ie7
Maybe your serverside code is faulty, or this is some browser/software specific security feature.
Thanks for the reply!
The form is working fine when submitted with the regular HTML submit button, so wouldn’t that mean that my PHP is good? I’m really not sure what is wrong…
It definately uploaded.
Using php, I checked via
tmp_name and size exist.
Your code probably has a logic error. For example, thinking a certain variable needs to exist(like the submit button’s name).
In the form action I have:
I don’t have anything with the submit button that could be making this happen. I double checked to make sure.
<input name=\“Submit\” type=\“submit\” value=\“Add\”>
I know what you mean about the submit button being checked but there is no check for Submit anywhere.
Could it be the action possibly? I’m out of ideas.
Start with something minimal which works
<form enctype="multipart/form-data" action="test.php" method="post">
<input name="a" type="file" onChange="document.forms.submit()">
Add your changes back in slowly until it stops working.