Luciuz Luciuz - 24 days ago 7
HTML Question

How open select file dialog via js?

$('#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.

Fix me.

Answer

I would create an input like this

<button id="id">Open</button>
<input id="yourinputname" type="file" name="yourinputname" style="display: none;" />

and some jQuery to trigger it:

$('#id').on('click', function() {
    $('#yourinputname').trigger('click');
});

Example: http://jsfiddle.net/QVAC7/