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
?
How to check an input type="file" has a file or not using jquery?
Asked Answered
Uhm, can you not just get the input element and then politely ask it for its "type" attribute? –
Pentatomic
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. –
Hindoo
$('#upload').bind('click', function(e){
if( $('#File1').val() != ""){
// file selected
}
else{
// no file selected
}
});
© 2022 - 2024 — McMap. All rights reserved.