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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:58:09+00:00 2026-05-26T00:58:09+00:00

I’m pretty new to JQuery, and this is probably not the best use case

  • 0

I’m pretty new to JQuery, and this is probably not the best use case to learn on, but it’s the project I have to do.

Basically I have a form, with a set of inputs where the values of the child inputs will be changed based on the values in the parent. (Using Ajax to retrieve the data sets).

Essentially:
Item List -> Available Sizes -> display Price for selected size

This is all pretty much straight forward, and I have something functioning for a single set of grouped inputs.

But I’m stuck on how to make this work for ‘N’ instances. I’m using an index on the element ids to group the related elements (i.e. input_name_[0 .. N]) and give unique ids throughout the document.

The HTML:

<form ...>
  <fieldset>
     <select id="item_list_0" name="item_list_0">
        <option value=''>Select an Item</option>
     </select>
     <select id="size_0" name="size_0">
           <option value="">Select Size</option>
     </select>
     <input id="price_0" name="price_0" size="10" value="Unit Price" />
 </fieldset>

 <fieldset>
     ..... repeated with inputs named: input_name_1
 </fieldset>
 .
 .  <!-- up to N --> fieldsets -->
 .
 </form>

JQuery script that works for a specific id “set” (i.e.: item_list_0)

    <script type="text/javascript" src="/js/jquery-1.6.2.min.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $("select#item_list_0").change(function(){
            $.getJSON(url,{data},
            function(json){
                var obj = json.pl.size;
                var options = '<option value="">Size</option>';
                for (var i = 0; i < obj.length; i++) {
                options += '<option value="' + i + '">' + obj[i] + '</option>';
              }
              $("select#size_0").html(options);
            });
          });

        $("select#size_0").change(function(){
            $.getJSON(url,{data},
            function(json){
                var price = json.pl.price;
                var size =  $("select#size_0").val();
                $("input#price_0").val(price[size]);
            });
        });

     }); // end ready function
    </script>

For reference the json returned from the url is:

{"pl":{"name":"item Name","price":["110.00","40.00","95.00"],"size":["LG","SM","MED"]}}

My challenges:
1. Need to remove the specific ID in the .click events to be dynamic for all ‘N’ of the field sets
2. Need to keep the relationships for the chains. (item_list_0.click should NOT effect size_1 option list)

I have looked at the jquery.selectChain plugin, and the jquery.cascade plugin, but neither seems to work for my particular situation.

  • 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-26T00:58:10+00:00Added an answer on May 26, 2026 at 12:58 am

    Apply a class to each of your select#item_list_N and select#size_N. You will get the following HTML:

    <form>
        <fieldset>
            <select id="item_list_0" name="item_list_0" class="item_list">
                <option value=''>Select an Item</option>
            </select>
            <select id="size_0" name="size_0" class="size">
               <option value="">Select Size</option>
            </select>
            <input id="price_0" name="price_0" size="10" value="Unit Price" />
        </fieldset>
    
        <fieldset>
            <!-- repeated with inputs named: input_name_1 -->
        </fieldset>
    
        <!-- up to N fieldsets -->
    
    </form>
    

    Then you could use a generic function to serve every single instance of your fieldset. The following is a raw draft of what I mean:

    $(document).ready(function() {
        $(".item_list").change(function() {
    
            // Let's assume that you only need to retrieve
            // a unique number to identify the fieldset.
            var uniquePart = $(this).attr('id').replace(/\D/g, '');
    
            // This part left almost untouched
            $.getJSON(url, {data}, function(json) {
                var obj = json.pl.size,
                    options = ['<option value="">Size</option>'];
    
                for (var i = 0, len = obj.length; i < len; i+= 1) {
                    options.push('<option value="' + i + '">' + obj[i] + '</option>');
                }
    
                // Here we apply the id number
                $("#size_" + uniquePart).html(options.join(''));
            });
        });
    
    
        $(".size").change(function() {
            var $this = $(this),
    
                // Same idea here
                uniquePart = $this.attr('id').replace(/\D/g, ''),
                size = $this.val();
    
            $.getJSON(url, {data}, function(json) {
                var price = json.pl.price,
    
                // By the way, ID selectors are told
                // to be more efficient without specifying a tag
                $("#price_" + uniquePart).val(price[size]);
            });
        });
    
    }); // end ready function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.