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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:34:58+00:00 2026-06-06T19:34:58+00:00

I need to use jquery to add and delete input fields based on user’s

  • 0

I need to use jquery to add and delete input fields based on user’s choice from a drop-down menu. I am able to achieve the add input fields feature. But got confused on the remove part. Can anyone give me some suggestions?
Here is the demo
HTML code:

<div class="form-fields">

<table>
<tr><th><label for="id_NOA">Number of Applications:</label></th><td><select name="NOA" id="id_NOA">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>

</select></td></tr>

<tr><th><label for="id_Ap_m">Application method 1:</label></th><td><select name="Ap_m" id="id_Ap_m">
<option value="" selected="selected">Select an application method</option>
<option value="1">Aerial</option>
<option value="2">Ground Sprayer</option>
</select></td></tr>

<tr><th><label for="id_Ar">Application rate:</label></th><td><input type="text" name="Ar" value="1" id="id_Ar" /></td></tr>

</table>

</div>

​jquery code:

$(document).ready(function() {
    i = 2;
    $("label[for='id_Ar']").html('Application rate 1:');   
    $('#id_NOA').change(function() {   
        var count_c = $(this).val();   
        while (i <= count_c) {
            if (i <= count_c) {    
                $('<tr><th><label for="id_Ap_m">Application method ' + i + ':</label></th><td><select name="Ap_m" id="id_Ap_m"><option value="" selected="selected">Select an application method</option><option value="1">Aerial</option><option value="2">Ground Sprayer</option></select></td></tr>').appendTo("table");    
                $('<tr><th><label for="id_Ar">Application rate ' + i + ':</label></th><td><input type="text" name="Ar" value="1" id="id_Ar" /></td></tr>').appendTo("table");
                i++;
            }

//this is the part I could not make it work
            if (i>count_c){

                $('.form-fields:last').remove();
                i--;

            }
        }
    });



});​
  • 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-06T19:34:59+00:00Added an answer on June 6, 2026 at 7:34 pm

    You want something like this http://jsfiddle.net/slash197/a98U8/5/ ?

    $(document).ready(function() {
    
        $('#id_NOA').change(function(){
            
            var total = $(this).val();
            
            //remove all
            $('.app_method').each(function(index){
                if (index != 0) $(this).remove();
            });
            $('.app_rate').each(function(index){
                if (index != 0) $(this).remove();
            });
            
            //create new ones
            for (var i = 2; i <= total; i++)
            {
                $('.app_method:first').clone().appendTo('table');
                $('.app_rate:first').clone().appendTo('table');
            }
            
        });
    
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <div class="form-fields">
        <table>
            <tr>
                <th><label for="id_NOA">Number of Applications:</label></th>
                <td>
                    <select name="NOA" id="id_NOA">
                        <option value="1">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                    </select>
                </td>
            </tr>
            <tr class="app_method">
                <th><label>Application method 1:</label></th>
                <td>
                    <select name="Ap_m">
                        <option value="" selected="selected">Select an application method</option>
                        <option value="1">Aerial</option>
                        <option value="2">Ground Sprayer</option>
                    </select>
                </td>
            </tr>
            <tr class="app_rate">
                <th><label>Application rate:</label></th>
                <td><input type="text" name="Ar" value="1" /></td>
            </tr>
        </table>
    </div>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use a jquery validation plugin and I need to add some extra checking,
I am trying to use jquery to add a class to my css menu
I have been using mootools for a year now. I need to use jquery
I use jquery picnet table filter - http://www.picnet.com.au/picnet-table-filter.html I need to display count of
I am need paint my image. I'm trying use JQuery in here this link:
I need a way to use the jquery .live() function to act on elements
I'm stucking with jQuery where I need to use closest to get the .text()
Using ASP.NET MVC + jQuery : I need to use some values owned by
I need help to use jConfirm with this existing code (php & Jquery &
While debugging jQuery apps that use AJAX, I often have the need to see

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.