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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:41:35+00:00 2026-06-01T15:41:35+00:00

I am using Eric Hynd’s wonderful multiselect plug in to populate a couple of

  • 0

I am using Eric Hynd’s wonderful multiselect plug in to populate a couple of drop downs.

One is the business units:
…

$('#lbBusinessUnits').multiselect({
height: "auto",
selectedList: 20
});

…
The second is the business areas (#lbBusinessAreas).
…

$('#lbBusinessAreas').multiselect({
selectedList: 20
}); 

…
The list of areas is updated when a unit is checked like this:

// Business Units List Box Change
$('#lbBusinessUnits').bind("multiselectclick", function (event, ui) {
    var selectedPeriod = $('#ddlSalesPeriods').val();
    var selectedUnit = ui.value;
    var selectedUnitText = ui.text;
    var checkedUnit = ui.checked;
    var areChecked = $(this).multiselect("getChecked").map(function () { return this.value; }).get();

if (areChecked.length > 0) {
    url = '/InvoiceException/LoadBusinessareasBySalesPeriodBusinessUnit';
    $.getJSON(url, { selectedSalesPeriod: selectedPeriod, selectedBusinessUnits: areChecked }, function (areas) {
    var areaSelect = $('#lbBusinessAreas');
    areaSelect.empty();
    $.each(areas, function (index, optionData) {
         areaSelect.append($('<option/>', { value: optionData.Id, text: optionData.Name }));
      });
    });
    }
else {
     var url = '/InvoiceException/LoadBusinessAreasBySalesPeriod';
    $.getJSON(url, { selectedSalesPeriod: selectedPeriod }, function (areas) {
    var areaSelect = $('#lbBusinessAreas');
    areaSelect.empty();
    $.each(areas, function (index, optionData) {
    areaSelect.append($('<option/>', { value: optionData.Id, text: optionData.Name }));
    });
  });
}
$('#lbBusinessAreas').multiselect("refresh");
}); 

The JSON results are handled by an MVC3 controller and are coming back correctly from the URL calls. I.E. the data returned looks right.

However the area box (#lbBusinessAreas) does not get updated properly after a click. It seems to be one click behind. It appears that there is a race condition occuring with the refresh of the box.

When I put it in Firebug and put a breakpoint at the point it calls multiselect(“refresh”) everything works properly when I step through the debugger and acts exactly like it should.

Is this truly a race condition where the refresh is finishing before the options get updated? Is it because it’s an ajax/getJson call?

Do I need to move the call to refresh out or figure out someway to ensure order of operation? I.E. the options need to finish updating and then the refresh needs to occur.

  • 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-01T15:41:36+00:00Added an answer on June 1, 2026 at 3:41 pm

    I thought a simple refresh after it was all said and done would work. A /headbonk moment as you realize that you have to wait for the success of the getJson calls to come back. So I had to move the refresh into the success function of each call. Posted change/answer here in case anyone else is having a “oh duh” moment.

    // Business Units List Box Change
    $('#lbBusinessUnits').bind("multiselectclick", function (event, ui) {
        var selectedPeriod = $('#ddlSalesPeriods').val();
        var selectedUnit = ui.value;
        var selectedUnitText = ui.text;
        var checkedUnit = ui.checked;
        var areChecked = $(this).multiselect("getChecked").map(function () { return this.value; }).get();
    
        if (areChecked.length > 0) {
            url = '/InvoiceException/LoadBusinessareasBySalesPeriodBusinessUnit';
            $.getJSON(url, { selectedSalesPeriod: selectedPeriod, selectedBusinessUnits: areChecked }, function (areas) {
                var areaSelect = $('#lbBusinessAreas');
                areaSelect.empty();
                $.each(areas, function (index, optionData) {
                    areaSelect.append($('<option/>', { value: optionData.Id, text: optionData.Name }));
    
                });
                **$('#lbBusinessAreas').multiselect("refresh");**
            });
        }
        else {
            var url = '/InvoiceException/LoadBusinessAreasBySalesPeriod';
            $.getJSON(url, { selectedSalesPeriod: selectedPeriod }, function (areas) {
                var areaSelect = $('#lbBusinessAreas');
                areaSelect.empty();
                $.each(areas, function (index, optionData) {
                    areaSelect.append($('<option/>', { value: optionData.Id, text: optionData.Name }));
                });
                **$('#lbBusinessAreas').multiselect("refresh");**
            });
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to JS and Jquery and I am using Eric Hynds jquery-ui-multiselect-widget
Is anyone using the techniques from Domain Driven Design? I've recently read the Eric
For example if i'm using eric meyer reset and i have to apply this
As Eric Gunnerson shows in this blog post, in C# you can nest using
Using Casting null doesn't compile as inspiration, and from Eric Lippert's comment: That demonstrates
I'm using the SimpleModal by Eric Martin (http://www.ericmmartin.com/projects/simplemodal-demos/) at www.1tryten.com/checkout.php. The code for loading
I am using Eric Martin's SimpleModal plugin 1.4.1 with JQuery 1.4.2 to display basic
All, I am trying to simplify a RelaxNG schema using Eric van der Vlist's
I am trying to populate a jqGrid search form using a SELECT element. In
I'm trying to write Eric Kidd's and Sigfpe's code for a probability monad using

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.