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" />
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.
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.
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.
<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" />
There should be
$('.send_upload')
but not $('.upload')
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