Possible Duplicate:
In JavaScript can I make a “click” event fire programmatically for a file input element?
I have naively tried the following to open the file picker programmatically with JavaScript (see fiddle here):
<input type='file'>
<script>
$(function () {
$('input').click();
});
</script>
The above doesn't work. How can I open the file picker of a input type='file'
with JavaScript?
For security reasons you can't trigger the dialog, unless it is as a response to some user triggered event. You could for instance trigger the dialog through a click on some other element:
$(function () {
$(".someElement").click(function () {
$('#f').click();
});
});
Working example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With