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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:04:57+00:00 2026-05-13T20:04:57+00:00

In my application, I have an HTML select box from which I remove and

  • 0

In my application, I have an HTML select box from which I remove and add items based on various user actions (the items become available/unavailable). However, I would also like all items to be displayed in preferred order, so every time I return an item to the select list, I need to re-sort in preferred order and select the preferred option. I’ve been unsuccessful thus far.

This is what I’ve got currently:

    function update_select (select_id) {
        // Rebuild given select box with appropriate options
        var s = $(select_id);
        s.empty();
        for (index in order_by_kind(selectable)) {
            var option = selectable[index];
            var s_option = $('<option value="' + option.value + '">' + option.desc + '</option>')
            s.append(s_option);
            if (index == 0) {
              s_option.attr('selected', true);
              console.log(s_option);
            }
        }
    }

If I log the results of order_by_kind(), the option values are sorted as desired. I empty the contents of the list and rebuild it in the desired order, but the item always is last in the list. Logging s_option shows that the option is set as selected, but the item is never selected in the UI. What might I doing wrong?

Edit:

My order_by_kind() function is below, for those who would like to verify that it functions correctly:

    function order_by_kind(obj_list) {
        var tmp = [];
        for (index in type_order) {   
          var kind = type_order[index];
          for (obj_index in obj_list) {
            var obj = obj_list[obj_index]
            if (kind == obj.value) {
              tmp.push(obj);
              // break out of the inner loop
              break;
            }
          }
        }
        return tmp
    }
  • 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-13T20:04:57+00:00Added an answer on May 13, 2026 at 8:04 pm

    The problem was that although I was iterating over the ordered list, I was still referencing the unsorted list in order to build my options.

    function update_select (select_id) {
        // Rebuild given select box with appropriate options
        var s = $(select_id);
        s.empty();
        // sort and write back the selectable items
        selectable = order_by_kind(selectable);
        for (index in selectable) {
            var option = selectable[index];
            var s_option = $('<option value="' + option.value + '">' + option.desc + '</option>')
            s.append(s_option);
            if (index == 0) {
              s_option.attr('selected', true);
              console.log(s_option);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: we have an application that generates reports from HTML (that may or may
I have table rows of data in html being filled from a CGI application.
I have a HTML application, partially HTML, partially VBscript, disguised as a form. What
I have a webview in my iPhone application, and I also have some html
I have a simple HTML (as HTA) application that shows strange behavior on Windows
I have a .net (3.5) WinForms application and want to display some html on
I have written some code in my VB.NET application to send an HTML e-mail
I have an game application I have written for Windows Mobile and I want
We have a Hibernate/Spring application that have the following Spring beans: <bean id=transactionManager class=org.springframework.orm.hibernate3.HibernateTransactionManager
In my application I have TextBox in a FormView bound to a LinqDataSource like

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.