Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically trigger "select file" dialog box

I have a hidden file input element. Is it possible to trigger its select file dialog box from a button's click event?

like image 678
tamakisquare Avatar asked Dec 21 '11 19:12

tamakisquare


1 Answers

If you're looking to have your own button to upload a file instead of using <input type="file" />, you can do something like:

<input id="myInput" type="file" style="visibility:hidden" /> <input type="button" value="Show Dialog" onclick="$('#myInput').click();" /> 

Note that I used visibility: hidden, instead of display: none. You cannot call the click event on a non-displayed file input.

like image 146
Mike Gwilt Avatar answered Sep 17 '22 21:09

Mike Gwilt