Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6793335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:05:18+00:00 2026-05-26T18:05:18+00:00

I have the following html code : <form name=uploadForm action= method=POST enctype=multipart/form-data> <input type=file

  • 0

I have the following html code :

<form name="uploadForm" action="" method="POST" enctype="multipart/form-data">
<input type="file" name="file_sub[]" />
<input type="file" name="file_sub[]" />
<input type="file" name="file_sub[]" />
<input type="file" name="file_sub[]" />
<input type="file" name="file_sub[]" />
<input type="button" onClick="javascript:submitform();" value="SUBMIT BTN" />
</form>

and here is the javascript function submitform() :

function submitform()
{
var minUpload = 1;
var uploadNo;
var count=document.uploadForm.file_sub.length;
for(a=0;a<count;a++)
        {

           if(document.uploadForm.file_sub.value != '')
               {
                 uploadNo++;
               }

         }

    if(uploadNo > minUpload){   
  document.uploadForm.submit();
    }else{
        alert('Please Upload Atleast ' + minUpload + ' files');
    }

}

the javascript is suppose to validate and make sure atleast minUpload of the the file fields a file inside them.

but for some reason when I try to get the length of the file in the function I get an error (according to the debugger of chrome, I get “Uncaught TypeError: Cannot read property ‘length’ of undefined” ) however I have tried the same thing with checkboxes and it works just fine. What am I doing wrong? is it even possible to do such task in js?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:05:19+00:00Added an answer on May 26, 2026 at 6:05 pm

    You have to refer to file_sub[]. Fixed function:

    var count = document.uploadForm["file_sub[]"].length;
    
    function submitform(){
        var minUpload = 1;
        var uploadNo;
        var files = document.forms['uploadForm']["file_sub[]"];
        var count = files.length;
        for(var a=0; a<count; a++){
            if(files[a].value != ''){
                uploadNo++;
            }
        }
    
        if(uploadNo > minUpload){   
            document.forms['uploadForm'].submit();
        } else {
            alert('Please Upload Atleast ' + minUpload + ' files');
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following HTML form <form action=https://sandbox.paypal.com/cgi-bin/webscr method=post id=paypalpost name=paypalpost> <input type=hidden name=rm value=2/>
I have the following HTML form: <div id=main> <form Id=search-form action=/ViewRecord/AllRecord method=post> <div> <fieldset>
I have the following code. def add_resume_link(name, form) link_to_function name do |page| html =
I have the following code: jQuery: $.ajax({ url: '/personcontroller/getperson', cache: false, type: POST, data:
I have something like this HTML structure : <form name=myvalue id=hello> <input type=text name=name
I have the following form <form id=myform method=post action=#> <div class=fields> <fieldset class=ui-widget ui-widget-content
I have one form as shown below: Page 1: <form name = form1 method=post
I have an HTML form using dojo and have the following code for a
I have the following html code: <h3 id=headerid><span onclick=expandCollapse('headerid')>&uArr;</span>Header title</h3> I would like to
I have the following html code. <html> <body> <div style=max-width:1600px; min-width:900px; > <table> </table>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.