 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Validate the size of input=file in HTML5?
You can try to run the following code to validate the size of input type file:
<!DOCTYPE html>    <html>       <head>          <script src="http://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>       </head>       <body>          <form >             <input type="file" id="myfile" data-max-size="32154" />             <input type="submit"/>          </form>          <script>             $(function(){                $('form').submit(function(){                   var val = true;                       $('input[type=file][data-max-size]').each(function(){                   if(typeof this.files[0] !== 'undefined'){                      var max = parseInt($(this).attr('max-size'),10),                      mySize = this.files[0].size;                      val = max > mySize;                      return val;                   }                });                return val;             });          });       </script>    </body> </html>Advertisements
 