I have a file upload control <input id="File1" type="file" />
in my page... How to check an input type="file" has a file or not using jquery on click of a button upload
?
-
Uhm, can you not just get the input element and then politely ask it for its "type" attribute?– user166390Commented Apr 15, 2010 at 5:38
Add a comment
|
3 Answers
You should use "required" instead of JQuery. By just one attribute it'll check input=file has file or not. Example:
<input type="file" required/>
-
not working for me, form still got sent with an empty field.– NelsonCommented Sep 24, 2019 at 23:07
$('#upload').bind('click', function(e){
if( $('#File1').val() != ""){
// file selected
}
else{
// no file selected
}
});