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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:25:52+00:00 2026-05-11T07:25:52+00:00

I have a dropdown in a web page with 3830 elements in it. I

  • 0

I have a dropdown in a web page with 3830 elements in it. I know, excessive but whatever.

In jquery I get the selected option value using the statement:

$( ‘#institutionCombo :selected’ ).val();

There is a noticeable pause before the selection is found. Once I get that value I insert it into a textbox on the page, so I know how fast. Plus I’ve checked it using breakpoints in Firebug.

If I go old school and use this javascript:

var div = document.getElementById( ‘maindiv’ );
var select = div.getElementsByTagName( ‘select’ )[ 0 ];
var ix = select.selectedIndex;
var instId = select.options[ ix ].value;

This speed is instananeous.

Is there something inherit in jquery that makes the :selected selector so slow when the numbers get too high? I’d like to stick with jquery throughout in my scripts, does anyone have a suggestion to speed up finding the selected option in jquery?

Thanks,

Craig

  • 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. 2026-05-11T07:25:53+00:00Added an answer on May 11, 2026 at 7:25 am

    There is no need to call the :selected when getting the val of a select box.

    The default behavior is to get the selectedIndex

    $( '#institutionCombo').val(); 

    As noted in the comment, If you need to access the text of that option you can use

    $( '#institutionCombo option[value=' + $( '#institutionCombo').val(); + ']').text(); 

    although if you know you need the text property and its different from the value you may just want to use the selectedIndex directly.

    var combo = $('#institutionCombo').get(0);  combo = combo ? combo : {selectedIndex: -1}; // handle no combo returned if (combo.selectedIndex < 0)   return; // nothing selected $('#institutionCombo option:eq(' + combo.selectedIndex + ')').text() 

    Here is the snippet from the jquery source (v1.3)

    val: function( value ) {     // ...       // We need to handle select boxes special     if ( jQuery.nodeName( elem, 'select' ) ) {         var index = elem.selectedIndex,             values = [],             options = elem.options,             one = elem.type == 'select-one';          // Nothing was selected         if ( index < 0 )             return null;          // Loop through all the selected options         for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {             var option = options[ i ];              if ( option.selected ) {                 // Get the specifc value for the option                 value = jQuery(option).val();                  // We don't need an array for one selects                 if ( one )                     return value;                  // Multi-Selects return an array                 values.push( value );             }         }          return values;       // ...   }, 

    When you call the :selected selector that is going loop through all the select elements decendents looking for the .selected property to be set and will return an array of any. Either way you do this it will loop all decendents, so don’t do this.

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

Sidebar

Ask A Question

Stats

  • Questions 67k
  • Answers 67k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Embed the Mark of the Web: <!-- saved from url=(0016)http://localhost… May 11, 2026 at 11:58 am
  • added an answer Yes, you can use the following to have ASP.NET ignore… May 11, 2026 at 11:58 am
  • added an answer I personally have had tables in production with 50 million… May 11, 2026 at 11:58 am

Related Questions

I have a dropdown list that stores name/value pairs. The dropdown appears in each
I have three values I need to align in a dropdown box. How can
I have a dropdown box and a literal tag inside an Update Panel. On
I have a dropdown, I have a datasource, I have AutoPostBack set to true
I have a requirement to add conditional disabled & class attributes to a dropdown
I have a page with two ContentPlaceHolders. One has a DropDown and another UpdatePanel
I have a custom built ajax [div] based dynamic dropdown. I have an [input]
I have a Tapestry PropertyModel for gender. Right now the dropdown just shows Male
So, I have an autocomplete dropdown with a list of townships. Initially I just
I have a drop down like this on my page: <p> <%= f.label :episode_id

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.