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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:40:30+00:00 2026-05-23T15:40:30+00:00

I have a dropdown list which is populated via a jquery ajax call when

  • 0

I have a dropdown list which is populated via a jquery ajax call when another dropdown list is changed, on the change() event, the code which does this:

    //dropdowns switching        
        $("#eventActivity").bind("change", (function()
        {                     
            $.ajax({
                type:"POST",
                url:"<?php echo site_url('events/get_locations_for_activity'); ?>" + "/" + $(this).val(),
                data: "activityID=" + $(this).val(),
                cache: false,
                dataType: "json",
                success:function(data)
                {
                    //empty the ddl
                    $(".locationDDL").children("select:first").children("option").remove();
                    //go through the json data returned and edit the drop down
                    for( var i = 0 ; i < data.length ; i++)
                    {
                        $(".locationDDL").children("select:first").append("<option value=\"" + data[i].locationID + "\">" + data[i].name + "</option>");
                    }

                }
            });
        })).change(); //force change to run once so it works on load for the first dropdown option

Now these dropdowns are on a dialog which pops up when the “edit” button is clicked. I’m passing the data through to the edit dialog so I can pre-fill the fields on the dialog. It all works fine except for setting the dropdowns to the correct values.
The code I use to do this is here:

$("#eventActivity").val(event.activityID);
$("#eventActivity").change(); //force the change handler to update the dropdowns
$("#eventLocation").val(event.locationID); 

As you can see, I set the value of the first dropdown, trigger the change event which should load new values to the second dropdown, then set the value of the second dropdown.
The problem is that the third line of code (setting #eventLocation) doesn’t work, instead the dropdown is left with it’s default value selected, the first value in the drowdown list.

Any suggestions are much appreciated!

  • 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-23T15:40:31+00:00Added an answer on May 23, 2026 at 3:40 pm

    You should set the value of the last dropdown in the success callback of your ajax request. If the last value setting depends on the ajax request being complete, you should have it in the callback. It is likely your request hasn’t been completed by the time that last value setting happens.

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

Sidebar

Related Questions

I have a ASP:DropDown list which is populated by the following: public void Fill1()
I have a dropdown list that is currently populated from a result set of
i have a drop down list which is populated dynamically from database table i.e
I currently have a dropdownlist which is populated via an SQLDataSource from the Module
I have a dropdown list populated with the list of names on my aspx
I am making ajax call using ASP.NET 3.5 to populate dropdown list as a
I have strange problem. I have class which behaves similar dropdown list. package test.view;
I have dropdown list control in one of my application and when I add
I have a dropdown list that stores name/value pairs. The dropdown appears in each
So, I have an autocomplete dropdown with a list of townships. Initially I just

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.