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

  • Home
  • SEARCH
  • 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 9120069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:32:47+00:00 2026-06-17T05:32:47+00:00

Description: I have many dropdowns on my page that all call a update price

  • 0

Description:

I have many dropdowns on my page that all call a “update price” function. This is so that when user selects an option, the price changes accordingly. There are many of these dropdowns and they all have similar names sizes-1, sizes-2, etc

Problem

I am finding myself copy/pasting extremely similar event binding code because I can’t figure out how to bind it through some sort of loop.

Example:

  • Static

    $( '.sizes-1' ).on('change', function() {
            sizes[0] = $(this).val();
            p.update_pricing( slider_values, price_fields, sizes, ); 
    });
    
  • Attempt at a loop ( not working )

    for( index = 0; index < number of divs; index++ ) {        
        $( '.sizes-' + index ).on('change', function() {
            sizes[ index ] = $(this).val();
            p.update_pricing( slider_values, price_fields, sizes, );                
        });
    }
    

There are going to be many .sizes divs on this page and I don’t want to copy/paste that static code 30+ times. I was wondering if anyone ran into a similar problem and knows a solution?

Thank you very much.

Edit: ( copy/pasted code )

for( index = 0; index < num_divs; index++ ) { 
    ( function( context_index ) {     
          $( '.sizes-' + context_index ).on( 'change', function() {
            sizes[ context_index ] = $(this).val();
            p.update_pricing( slider_values, price_fields, sizes );                
         });
    } ( index ) ); 
}
  • 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-17T05:32:48+00:00Added an answer on June 17, 2026 at 5:32 am

    You can add a CSS class to all of your select HTML elements and then, use jQuery CSS selector to retrieve all of them

    <select class="selectSpecial" id="sizes-1">...</select>
    <select class="selectSpecial" id="sizes-2">...</select>
    etc
    

    And you retrieve all your select with

    $(".selectSpecial").on('change', function(changeEvent) {
    
        var index = parseInt($(this).attr('id').replace('size-', '')) - 1;
        sizes[index] = $(this).val();
        p.update_pricing( slider_values, price_fields, sizes);
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many objects with a property description where is like this: description: This
I have an NStextView that loads a description from a JSON source. The NSTextView
I have something like this: [Description(Sets the color.), Category(Values), DefaultValue(Color.White), Browsable(true)] public Color MyColor
I have an enum with Description attributes like this: public enum MyEnum { Name1
I have a many to many relationship as follows: Products ProductID Description ProductFeatures ProductFeatureID
First of all, excuse me if it sounds duplicate. I have visited so many
I have thought about making enums for all my fields, but that doesn't look
I have many relations of this type, but I can't see why this one
I have a query that looks like the following: select c.[Name], c.Description, c.ID, cd.StartDateTime
I have many javascript files referenced in an HTML file. There is a call

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.