
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
Limit Maximum Items on Multiple File Input
To allow multiple file uploads in HTML forms, use the multiple attributes. The multiple attributes work with email and file input types.
For limiting maximum items on multiple inputs, use JavaScript. Through this, limit the number of files to be uploaded. For example, let’s say only 2 files to be uploaded at once.
You can try to run the following code to learn how to use multiple attributes in HTML. With that, we will limit the number of files uploaded using JavaScript.
Example
<!DOCTYPE html> <html> <head> <title>HTML file upload</title> </head> <body> <form> <input type="file" action="/action_page.php" name="name" multiple><br/> Upload multiple files, and click Submit.<br> <input type = "submit" value = "submit"> </form> <script> $(function(){ $("input[type = 'submit']").click(function(){ var $fileUpload = $("input[type='file']"); if (parseInt($fileUpload.get(0).files.length) > 3){ alert("You are only allowed to upload a maximum of 3 files"); } }); }); </script> </body> </html>
Advertisements