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
?
PHP empty() Function The empty() function checks whether a variable is empty or not. This function returns false if the variable exists and is not empty, otherwise it returns true. The following values evaluates to empty: 0.
To check if the input text box is empty using jQuery, you can use the . val() method. It returns the value of a form element and undefined on an empty collection.
Just use: $("input:empty"). length == 0; If it's zero, none are empty.
if (jQuery('#File1').val()) { /* There are files */ }
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/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With