Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload File with one button

How can I make a button in the html you need to send files that allow you to select the file and then sending it on the page that I want without using a button to select the file and a button to send it to another page? Thanks you!

like image 771
Filippo Alessi Avatar asked Jul 10 '12 11:07

Filippo Alessi


2 Answers

<form>
    <input type="file" onchange="this.form.submit()" /> 
</form>
  • jsFiddle Demo
  • form.submit() on MDN
like image 119
kapa Avatar answered Oct 21 '22 09:10

kapa


You should use

HTML

<form id="form">
 <input type="file" id=file"/> 
</form>

more info: http://www.w3.org/wiki/HTML/Elements/input/file

Jquery

$("#file").onchange(function () {
 $("#form").submit();
});
like image 31
Mateusz Rogulski Avatar answered Oct 21 '22 10:10

Mateusz Rogulski