Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check an input type="file" has a file or not using jquery?

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?

like image 307
ACP Avatar asked Apr 15 '10 05:04

ACP


People also ask

How do you check input type file is empty or not in JS?

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.

How check input field is empty or not in jQuery?

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.

How do you check if all inputs are filled jQuery?

Just use: $("input:empty"). length == 0; If it's zero, none are empty.


2 Answers

if (jQuery('#File1').val()) { /* There are files */ }
like image 177
Quentin Avatar answered Sep 24 '22 02:09

Quentin


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/>
like image 21
Hardik Sondagar Avatar answered Sep 21 '22 02:09

Hardik Sondagar