Saturday, August 6, 2016

Check if files is empty or not using jQuery


You can check if a file field is empty or not using jquery Suppose you have an input field like this
<form id="myForm">
 <input type="file" id="myFile"/>
 <a href="javascript:void(0);" id="check">Check</a>
</form>
You can check if the filed is empty or not like this
<script>
$(document).on('click', '#check', function(){
 if ($('#myFile').get(0).files.length === 0) { 
  console.log("No files selected."); 
 }
})
</script>