$('#id').click();
It doesn't work on Chrome 26 on Mac OS.
The problem actually is creation "upload" widget that can be integrated in a form. Widget will consists of two parts. The first part is div with initiator button and error/success messages. I think the way is put another form as the second part with file input and submit file into the iframe. After submition we fill hidden field in first part in main form or show errors in the same.
Easy way is adding file-form into main-form, but it's prohibited.
Use the type="file" Attribute in HTML and onchange Method in JavaScript to Open File Dialog. We will create a button element in the following instance, and an onclick attribute will follow this. This will trigger a function in the JavaScript file.
If you cannot open your INPUT file correctly, try to right-click or long-press the file. Then click "Open with" and choose an application. You can also display a INPUT file directly in the browser: Just drag the file onto this browser window and drop it.
I would create a button and an invisible input like so:
<button id="button">Open</button> <input id="file-input" type="file" name="name" style="display: none;" />
and add some jQuery to trigger it:
$('#button').on('click', function() { $('#file-input').trigger('click'); });
Same idea, without jQuery (credits to @Pascale):
<button onclick="document.getElementById('file-input').click();">Open</button> <input id="file-input" type="file" name="name" style="display: none;" />
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