Load dropdown with .ajax then set the selected value with jQuery

Recently I encountered an issue when trying to set the selected value of a dropdown list.  I was using the jQuery .ajax method to populate the select list and this was working, but when I tried to set the selected value using jQuery, I was not able to.  I should have realized that .ajax makes a async call by defualt and there is no garuntee the list will be populated when you try to set the selected value.

There are a couple of solutions.  You can set the selected value in the success event handler or you can set async to falst in the .ajax method:

async: false,

Comments are closed