Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get the value of input type file , and alert if empty

Tags:

how to alert if input type file is empty !?

this is my jquery code but i didnt know how to get the value

$('.upload').live("click",function() {     var imgVal = $('#uploadImage').val();     if(imgVal=='')     {         alert("empty input file");      }     return false;  });   <input type="file" name="image" id="uploadImage" size="30" /> <input type="submit" name="upload"  class="send_upload" value="upload" /> 
like image 948
Mac Taylor Avatar asked Jul 20 '10 17:07

Mac Taylor


People also ask

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

We get our input element with document. getElementById() and check the length of the files property, which an input of type file has. If it's empty, we alert the user that no file has been selected.

How do you check a file is empty or not in PHP?

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 type is empty or not in laravel?

It is very easy to check if uploaded file or image empty or not if you are using core PHP. But as we know laravel 5 provide us object of file, So we can not determine using empty(). However, we can simply do it using hasFile() and isValid() of laravel predefine.


2 Answers

<script type="text/javascript"> $(document).ready(function() {     $('#upload').bind("click",function()      {          var imgVal = $('#uploadImage').val();          if(imgVal=='')          {              alert("empty input file");           }          return false;       });  }); </script>   <input type="file" name="image" id="uploadImage" size="30" />  <input type="submit" name="upload" id="upload"  class="send_upload" value="upload" />  
like image 114
Fosco Avatar answered Sep 26 '22 21:09

Fosco


There should be

$('.send_upload') 

but not $('.upload')

like image 33
Denis Avatar answered Sep 26 '22 21:09

Denis