How to use jQuery to determine if a file is selected, a selected file?

And then tell the file name?

+7
javascript jquery html css
source share
2 answers

That should be enough:

alert($('#your_input_box').val()); 

The file selection field is just the input field from which I can tell. More on this question: jQuery: get the file name selected from <input type = "file" /> .

+20
source share

To determine if a file has been selected, you can find out the length of the input file

 $("#bCheck").click(function() { // bCheck is a input type button var fileName = $("#file1").val(); if(fileName) { // returns true if the string is not empty alert(fileName + " was selected"); } else { // no file was selected alert("no file selected"); } }); 
+8
source share

All Articles