In an html page ,I am adding an input element.
<input type="file" name="fileselect" id="fselect"> </input>
I wanted to execute a javascript function ,when a user selects a file.Suppose I want to write to the console too.
Is jquery select() the correct function to check if user has selected a file? I tried like this
$(document).ready(function(){
$('#fselect').select(function(){
console.log('selected');
myfun();
});
});
function myfun(){
alert('you selected a file');
}
For some reason, when I select a file using the input element,nothing is written to console and no alert box appears..Is the select() call coded wrong?
The event you want is change, not select.
From the docs:
And for change: