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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:51:27+00:00 2026-06-16T19:51:27+00:00

Is there a proper way/design for doing this? or must I combine them into

  • 0

Is there a proper way/design for doing this? or must I combine them into one function/event and base them off the values returned from the Ajax?

I have a dropdownlist with two Change Events/Functions like so,

$(document).ready(function () {
    $("#ddlFacilityDatabases").change(UpdateCategoriesList).change(UpdateReportsList);
}

Both functions modify options on “#ddlCategories” and “#ddlReports”.
UpdateCategoriesList() modifies my “#ddlCategories” Options and UpdateReportsList() modifies my “#ddlReports” Options.

Here is one of my Functions (Only posting one since they’re nearly Identical, just changes a couple locations and names)

function UpdateCategoriesList() {

    // Disable the Dropdown.
    $("#ddlCategories").attr("disabled", true);

    // Get Selection Value.
    var Selection = {
        "FacilityDatabaseName": $("#ddlFacilityDatabases").val()
    };

    // Send JSON to /Select/getCategories/.
    $.ajax({
        url: "/Select/getCategories/",
        type: "GET",
        dataType: "html",
        data: Selection,
        success: function (response, textStatus, jqXHR) {
            // Parse Array.
            var Categories = JSON.parse(response).categories;

            // Clear Categories DropDownList.
            $("#ddlCategories").children("option").each(function () {
                if ($(this).val() != "") {
                    $(this).remove();
                }
            });

            // Add New Categories.
            var length = Categories.length;
            for (var i = 0; i < length; i++) {
                if (Categories[i] != null || Categories[i] != "") {
                    $("#ddlCategories").append("<option value=\"" + Categories[i] + "\">" + Categories[i] + "</option>");
                }
            }
        },
        complete: function () {
            // re-enable dropdownlist
            $("#ddlCategories").attr("disabled", false);
        }
    });
}

The Problem is when I add them both to the event handler like above it runs them but the page updates the dropdownlists after both the functions run. I need the first one to update the page then the second one to do so since the second is dependent on the first’s changes.

  • 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-16T19:51:29+00:00Added an answer on June 16, 2026 at 7:51 pm

    I think your problem is that you want to impose an ordering on asynchronous calls. If UpdateReportsList must come after UpdateCategoriesList, then you have two options.

    Option 1: as Neal pointed out, call the second function from within the ajax call of the first.

    Option 2: make both calls blocking, instead of asynchronous, like this:

    $.ajax(
        url: ...,
        async: false,
        ...
    );
    

    then call

    $("#ddlFacilityDatabases").change(function (){
        UpdateCategoriesList();
        UpdateReportsList();
    });
    

    Overall, I think the first option is better, if you can change those two functions.

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

Sidebar

Related Questions

Is there a proper way, equation or technique in general to say, My web
Is there a proper way yet to unit test views with the aspx view
I wonder, if there is a proper way to remove the default close button
Maybe there is a proper term for this, but what if you want to
is there are proper subversion client for ruby, that could be used to manage
I'm not sure if there is a proper term for what I want to
There have been several questions over the past few days about the proper use
I'm new to coffeescript, and while there is extensive information concerning the proper method
There is a column that exists in 2 tables. In table 1, this column
My application is following the MVC design pattern. The problem I keep running into

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.