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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:33:49+00:00 2026-06-16T16:33:49+00:00

I have an HTML select element that allows multiple selection. I am populating the

  • 0

I have an HTML select element that allows multiple selection. I am populating the options with the results of an ajax request. I am adding custom attributes to the options. In one instance, when another ajax request completes, I would like to update the multi-selected values. I have the following javascript method to do this selection:

// select = id of the select control.
// selected = list of json objects with an id representing those that are selected.
updateSelection = function( select, selected ) {
    $('#'+select+' option').each( function() {
        var item = $(this);
        $.each(selected, function() {
            item.removeAttr( "selected" );
            if ( this.id === parseInt(item.attr("optionId"), 10 )) {
                alert( "selecting " + item.text());
                item.attr("selected", true );
            }
        });
    });
};

The HTML before the method is run looks like this:

<select id="putPlatforms" multiple="multiple">
    <option optionid="1" optionversion="1">PC</option>
    <option optionid="3" optionversion="1">Xbox 360</option>
</select>

In the case where only ‘PC’ is selected then the selection is made and reflected in the UI. The same if only ‘Xbox 360’ is selected. If BOTH options should be selected I see the alert stating that both will be selected, but only Xbox 360 is selected.

  • 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-16T16:33:50+00:00Added an answer on June 16, 2026 at 4:33 pm

    Using the answer to this question I was able to make it work. I changed my function to the following:

    // select = id of the select control.
    // selected = list of json objects with an id representing those that are selected.
    updateSelection = function( select, selected ) {
        $('#'+select+' option').attr('selected', false );
        $.each(selected, function() {
            $('#'+select+' option[optionid='+this.id+']').attr('selected', true );
        });
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a select html element that is populated with jquery inside an ajax
I have Jquery code that checks on .change status of HTML select element and
I have a simple webpage that adds & deletes options from a select element
I have an HTML select element with some countries as the options. <select id=countryLocation
I have n number of select elements in an html page that are used
I have a html element (like select box input field) in a table. Now
I have a html combo/select. When the user selects a element, I want to
i have a html select with options in my views . onchange i want
I have an HTML page (written in .NET MVC) that allows a user to
I have an html select element which I would like to style for print

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.