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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:05:35+00:00 2026-06-03T14:05:35+00:00

NOTE: using jQuery 1.3.2 (Yep I’m upgrading but still need to be at 1.3.2

  • 0

NOTE: using jQuery 1.3.2 (Yep I’m upgrading but still need to be at 1.3.2 for this)

Looking for a better way to implement this

HTML Element (This is coming from a custom PHP framework and is very cumbersome to make changes to):

<select id="car[0][car_id]" name="car[0][car_id]">
    ... 100+ options
</select>

I can add another drop down dynamically which looks like this:

<select id="car[1][car_id]" name="car[1][car_id]">
    ... 100+ options
</select>

and

<select id="car[2][car_id]" name="car[2][car_id]">
    ... 100+ options
</select>

Now I’m iterating through them like this:

function showCarinfo() {
    for ( var car_number = 0; $("#car\\["+car_number+"\\]\\[car_id\\]").length > 0; car_number++ ) {
        // do stuff
    }
}

on change selection:

$("input[name*=car_id]").change(function(){
    // display info for each car selected from each drop down select menu
    showCarinfo(); 
});

Is there a better way to implement the on change and iterating methods? I am using the ‘Attribute Contains Selector’ ( http://api.jquery.com/attribute-contains-selector/ ) but looks like it’s causing a big performance issue with the on change event.

UPDATE:

I’ve replaced the * with $ to search the last part and this (I think) does help with performance a little but still looking if this is the best solution

$("input[name$=car_id]").change(function(){
    // display info for each car selected from each drop down select menu
    showCarinfo(); 
});
  • 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-03T14:05:37+00:00Added an answer on June 3, 2026 at 2:05 pm

    The performance issue is in your showCarinfo function. You’re preforming DOM selection in a loop.

    Don’t do that. Instead cache the selection…

    function showCarinfo() {
        var cars = $("input[name*=car_id]");
        for ( var car_number = 0; car_number < cars.length; car_number++ ) {
            cars.eq(i); // do stuff
        }
    }
    

    or you can use .each()

    function showCarinfo() {
        $("input[name*=car_id]").each(function() {
            // do stuff
        });
    }
    

    Also, if the only thing the handler is doing is calling that function, a small optimization would be to do this…

    $("input[name*=car_id]").change(showCarinfo);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Note: I'm using jQuery below, but the question is really a general JavaScript one.)
I have tried this, (note that I am using jQuery): function HandleFileButtonClick() { 1.
Note: I'm using Google Chrome Currently I have this test page http://www.evecakes.com/doodles/canvas_size_issue.htm It should
[NOTE: I'm using ASP.NET MVC2 RC2.] I have URLs like this: /customers/123/orders/456/items/index /customers/123/orders/456/items/789/edit My
NOTE: I'm using a BSD based system so if I remember correctly this means
First as a note I am using this plugin in a Rails app. Ok
Note: In this question I'm using the term autocomplete (or iterative search) to refer
How to send a javascript array to PHP using Jquery Ajax.(Note: i will get
I'm sending post data using jquery, but when I retrieve it in asp all
Note: I'm using jQuery and jQuery Mobile. I have a mobile page which seems

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.