what listeners are called when a file is selected from a file chooser in javascript

DitR picture DitR · May 22, 2013 · Viewed 9.8k times · Source

I'm working on creating an upload button for my website but I'm unable to trigger events based on when the file is selected for the upload. I was under the impression that the .submit function did this but I'm unable to get any results from this. HTML

    <input type="button" id="uploadbutton" value="Upload File" />
    <form action="includes/uploader.php" method="POST" id="fileupload_form">
        <input id="fileupload" type="file" name="files[]" multiple style="display:none;">
        <input id="server" type="hidden" name="server" value="upload">
        <input type="hidden" id="storeA" value="statement_upload" name="storeA">
    </form>

Javascript/jQuery

var fileupload = $("#fileupload");

$("#uploadbutton").click( function(){
    fileupload.click();
});

$("#fileupload_form").submit( function(e){}

This javascript function will not run when trying to select the file and no errors are given. Any and all help is appreciated!

Answer

Grzegorz Kaczan picture Grzegorz Kaczan · May 22, 2013

Listen on fileupload.on('change', function(){}) to get what and when was chosen in file selector.