Reputation: 24853
This is my input tag:
<input id="myId" class="button" name="myFile" type="file">
As soon as the user chooses a file, I would like to get the name of the file, to display it and give the user some feedback. I know that I can get the filename in Javascript (using Jquery) like so:
var fileName = $('#myId').val();
However, I would like to do a function call as soon, as the user picks a file. If a add an onclick-even at the "myId" Tag, this event will get called as soon as the user clicks the button, but BEFORE he picks a file. What event is being triggered when the user chooses a file? How can I call a function right after the user picks a file?
Upvotes: 2
Views: 5437
Reputation: 4098
Since you are already using jQuery, the solution is quite straight forward:
$("#myId").change(function(){
doIt();
});
Upvotes: 4