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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:40:53+00:00 2026-05-12T11:40:53+00:00

I have a form with a stage that has a dynamic number of groups

  • 0

I have a form with a stage that has a dynamic number of groups of fields, where the number is based upon answers in the previous stage.

I’m generating the fields server-side as an array, i.e.

<input id="foo[0]"...
<input id="bar[0]"...

<input id="foo[1]"...
<input id="bar[1]"...

<input id="foo[2]"...
<input id="bar[2]"... etc

No matter the number, all fields are required & I also need to validate against type & number of digits in some cases. I’m using the jQuery validate plugin for client-side processing (yes, backed up with server-side stuff too) & the validation can’t be done inline as the form needs to pass XHTML Strict (EDIT: see my addendum below).

My problem is that I can’t work out how to use validate with a dynamic number of fields. Here’s what the validate syntax typically looks like for the rest of the form:

$(document).ready(function() {

    // validate stage_form on keyup and submit
    var validator = $("#form_id").validate({

        // rules for field names
        rules: {

            name: "required", 
            address: "required",
            age: { required: true, number: true }

        },

        // inline error messages for fields above
        messages: {

            name: "Please enter your name", 
            address: "Please enter your address",
            age: { required: "Please enter your age", number: "Please enter a number" }

        }

    });

});
  • 1 1 Answer
  • 1 View
  • 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-12T11:40:53+00:00Added an answer on May 12, 2026 at 11:40 am

    actually it should work If you’d use classes instead of initializing rules as validate() options.

    Markup:

    <input id="foo[0]" class="required"
    <input id="bar[0]" class="required number"
    
    <input id="foo[1]" class="required"
    <input id="bar[1]" class="required email"
    

    jQuery:

    $(document).ready(function() {
    
      var validator = $("#form_id").validate({
        messages: {
                name: "Please enter your name", 
                address: "Please enter your address",
                age: { 
                   required: "Please enter your age", 
                   number: "Please enter a number" 
                }
    
        }
    
      });
    
    });
    

    hope this works.
    Sinan.

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

Sidebar

Related Questions

I have a dynamic form that is generating a country list. My problem is
I have a very complicated form which has multiple stages in it. Each stage
I have form where are 2 input fields and then i have dynamic dataTables
I have created my application that has search form and below contains results for
i currently have a form that has several check boxes, once all the boxes
I have a Form (Form1) that has implemented asynchronous TCP/IP sockets. I have an
In an html form I have a checkbox that has a label. When you
I have a form that has target=_blank on submit. I want to validate the
I have a page that has a form and a generated content area that
I have a script which validates each stage of a form and adds 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.