I have a web page where I want to prompt the user for a file to upload, but I don't want to display the <input type="file"/> element.
I have a button that triggers the file dialogue to display, but the code doesn't wait for the dialogue to return.
Is there an event I can hook into that is raised when the file dialogue returns? Is there some other thing I've not thought of?
This is what I have at the moment, it uses an alert to block the code. I want something less hacky.
function importValues(e)
{
    var f = document.getElementById('file');
    f.click();
    alert('loading'); //hack to make the code wait for the user to choose a file before making the ajax call
    var formdata = new FormData(jQuery('#frmImport')[0]);
    jQuery.ajax({
        url: 'importFile',
        type: 'POST',
        data: formdata,
        chache: false,
        contentType: false,
        processData: false,
    });
}
                i think you need to refactor your code and handle native file upload events.
if you have some element like file dialog 
<input type="file" name="file" id="file" /> 
then you can hook up to its events and specially to onchange
$(function(){
    $("#file").change(function(e){ alert('selected') });
});
jsFiddle
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