Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically submitting a form when an upload file is chosen

I have a HTML page with the following input tag:

...
<input type="file" id="browseContactImageButton" />
... 

Clicking the button on the page results in Open File Dialog. If I want to do the actual uploading, I need another button to click (submit), because this input file button is used just to provide the path to the file.

Is it possible to click the browse button, select the file and to start the uploading function immediately after the file has been chosen? If yes, could anyone provide the code snippet? Thanks.

like image 399
Boris Avatar asked Jan 31 '11 22:01

Boris


People also ask

How do i auto submit an upload form when a file is selected?

Instant form submission using JavaScript In the above code, we have used the onchange method of JavaScript. This method helps to detect the changes of the file input field. After that, we have used the submit() method to submit the form automatically.

How do I automatically submit a form without clicking?

Submit a Form Using JavaScript The most simple way to submit a form without the submit button is to trigger the submit event of a form using JavaScript. In the below example we are going to create a function to submit a form. We will set that function at onclick event of a div tag.

How do you submit form only once after multiple clicking on submit?

Disabling the Submit Button In practice this can cause a form to be submitted, or some other event triggered, more than once. The second button however will only accept a single click and ignore all subsequent clicks. The trick is to use JavaScript to set the disabled property of the button to true.


1 Answers

If you want the form to submit after the user has made their selection, then simply add

<input type="file" onchange="this.form.submit();" ..... >
like image 138
John Cartwright Avatar answered Sep 18 '22 23:09

John Cartwright