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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:11:21+00:00 2026-05-23T10:11:21+00:00

Suppose I have a drop down box to define how many row of input

  • 0

Suppose I have a drop down box to define how many row of input box, then generate the designated rows of input box, after that each row of input box with attach a drop down box, it can define how many input box of each row, illustrated as below:

enter image description here

Could anyone suggest the snippet for this procedure?

Thanks

  • 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-23T10:11:21+00:00Added an answer on May 23, 2026 at 10:11 am

    I will not give you specific snippet for this, but will give you some tips instead. Here they are:

    1. Think about HTML structure for this (eg. separate first select from the rest of the form, eg. give the rest of the form a <div> with form-dynamic-fields class so it will serve as a container for dynamically generated fields),
    2. Use jQuery’s .delegate() function to attach events (delegate them to the select boxes within dynamic fields),
    3. Depending on the selection of specific select field, add, remove or replace appropriate rows (when changing main select’s field value) or fields (when changing value of select for specific row),
    4. You should probably use onchange event.

    Example usage of .delegate() function can be like that:

    jQuery('.form-dynamic-fields').delegate('select', 'change', function(event){
        var fields_in_a_row = jQuery(this).val(); // how many fields in current row
        // insert or remove appropriate number of fields for current row here
    });
    

    and it will work for every <select> fields generated dynamically as far as the container with class form-dynamic-fields remains their parent element and is not deleted.

    So, given you the clue about how you can structure your form, how to attach events, what should they do and what event should you use, I would like to…

    …encourage you to test different solutions and share information about the progress you have made with solving this issue.

    EDIT:

    Some working example to encourage you more (see jsFiddle):

    • HTML:

      <form class="form-dynamic" action="" method="post">
          <select name="number_of_rows">
              <option>0</option>
              <option>1</option>
              <option>2</option>
              <option>3</option>
              <option>4</option>
          </select>
          <div class="form-dynamic-fields">
      
          </div>
      </form>
      
    • JavaScript (executed onDomReady):

      jQuery('.form-dynamic').delegate('select[name="number_of_rows"]', 'change', function(event){
          var field_template = '<input type="text" name="row[]" /><br />';
          var howmany = parseInt(jQuery(this).val());
          var container = jQuery(this).parent('.form-dynamic').find('.form-dynamic-fields').empty();
          if (howmany > 0){
              for (i=1; i<=howmany; i++){
                  container.append(jQuery('<div class="form-dynamic-row"><input type="text" name="rows[' + i +'][]" /> <select name="rows_counts[]" data-row-id="' + i + '"><option>1</option><option>2</option><option>3</option><option>4</option></select></div>'));
              }
          }
      });
      
      jQuery('.form-dynamic').delegate('select[name="rows_counts[]"]', 'change', function(event){
          var parent = jQuery(this).parent('.form-dynamic-row');
          parent.find('input[type="text"]').remove();
          var howmany = jQuery(this).val();
          var row_id = jQuery(this).attr('row-id');
          for (i=1; i<=howmany; i++){
              parent.prepend('<input type="text" name="rows[' + row_id + '][' + i + ']" />');
          }
      });
      

    What you need to do is:

    • clean the code,
    • add some styling (so the fields have proper width),
    • check and eventually fix name attributes of <input> fields,
    • fix problems you may encounter when implementing it,

    I hope it helped 🙂

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

Sidebar

Related Questions

Hi I have a combo box having 5 drop down items in Tab1 and
I have this simple Select box that is suppose to store the selected value
I have a form that once you select from a drop-down list and select
Suppose I have a drop-down list like: <select id='list'> <option value='1'>Option A</option> <option value='2'>Option
I have a form that is a drop down select list. I also have
Suppose I have a drop down menu: <select id=color> <option value=white selected=selected>White</option> <option value=black>Black</option>
I have an html table of data with a drop down box in each
Suppose I have the following HTML: <form id=myform> <input type='checkbox' name='foo[]'/> Check 1<br/> <input
Suppose you have a subsystem that does some kind of work. It could be
I have a drop-down selector and need to load other parts of the form

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.