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 8812565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:38:01+00:00 2026-06-14T03:38:01+00:00

Hi my problem is that i have a form that expands dynamically. I will

  • 0

Hi my problem is that i have a form that expands dynamically. I will use it to upload the files to e-commerce website to upload the products pictures, i want to limit the size and filter the extensions before upload, but i am a noob with javascript, and/or jQuery…

i need help to validate those, because i think i can handle the PHP side of things 🙂 here is my experimental code:

<script language="Javascript" type="text/javascript">
var counter = 1;
var limit = 10;
function addInput(divName){
     if (counter == limit)  {
          alert("You have reached the maximum of " + counter + " fotos");
     }
     else {
          var newdiv = document.createElement('div');
          newdiv.innerHTML = "Foto " + (counter + 1) + " <br><input type='file' name='myInputs[]'>";
      document.getElementById(divName).appendChild(newdiv);
      counter++;
 }
}
</script>

<form method="POST" enctype="multipart/form-data"> 
     <div id="dynamicInput">
          Foto 1<br><input type="file" name="myInputs[]">
 </div>
 <input type="button" value="Add more fotos" onClick="addInput('dynamicInput');">
</form>

thank you in advance

EDIT:

ok i can verify the type of files submitted but i cannot loop through the different file fields...

i have this code on fiddle http://jsfiddle.net/Glink/sGCeK/

it may help you help me...

one more question, if i have my code in xHTML is it very hard to update to HTML5?

once again thank you in advance...

  • 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-06-14T03:38:02+00:00Added an answer on June 14, 2026 at 3:38 am

    You’re on the right track, however you should try using jQuery with your javascript. I think you will find things a lot easier. I’ve written a quick example of what I think you are looking to accomplish. If you need further explanation, feel free to ask.

    Example

    HTML:

    <form method="POST" enctype="multipart/form-data" id="theForm"> 
     <label class="dynamicInput">
          Foto 0<input type="file" name="myInputs1">
     </label>
    <br/>
    </form>
    

    JS:

    var counter = 1;
    var limit = 10;
    
    
    $("#addButton").click(function(){
    htmlString = '<label class="dynamicInput">Foto'+ counter +'<input type="file" name="myInputs '+ counter + '"></label><br/>'
    
     if(limit > counter)
    $("#theForm").append(htmlString);
    counter++;
    });
    ​
    

    UPDATE: Miss read the question, I thought you were looking just to append new fields to the box. For file size of uploads, you can get that number by using:

    this.files[0].fileSize
    

    Example: Updated Example

    As for checking extensions there isn’t an easy way that i’ve found to do this. You will probably will need to use some sort of regex. Something like this:

    File Extension Example

    That should put you on the right path.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HTML form where I use several buttons. The problem is that
Fact: I'm not that good with jQuery. Problem: I have a form containing dynamically
i have bought a template that have built in contact form problem is that
I have an InfoPath form with several fields on, the problem is that one
I have a following problem, I have HTML form that uploads a file with
The problem I am encountering is that for my login form I have to
I have a dropdown in my form that has a problem to populate when
I have a problem. The client is claiming that a prize signup form I
I want to make an form for purchasing tickets. The problem is that for
The problem that I have is somehow very specific. I have to implement a

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.