How to limit maximum items on multiple 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.


Live Demo

<!DOCTYPE html>
      <title>HTML file upload</title>
         <input type="file"  action="/action_page.php"  name="name" multiple><br/>
         Upload multiple files, and click Submit.<br>
         <input type = "submit" value = "submit">
            $("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");