0

I have three dropdowns I am trying to dynamically populate when an HTML form loads. They all use API callback functions provided by a third-party cloud database provider to retrieve the data and populate the dropdowns. The problem I am encountering is that only the last one populates. Here is how I'm calling the functions:

$(function ()
{
    PopulateDropdown('OwnerList');
});

$(function()
{
    PopulateDropdown('ClientList');
});

$(function ()
{
    PopulateDropdown('AssignedToList');
});

The text inside the parentheses are the IDs of the dropdowns (select elements) in the HTML.

The only dropdown that ever gets populated is whichever the last one in the list is. The code as shown above populates only the AssignedToList dropdown. If I move the call to populate the AssignedToList to the top, moving the ClientList to the bottom, only the ClientList dropdown populates. I am fairly new to JavaScript and jQuery, so I'm sure there's a way to ensure all three calls work properly. I have Googled everything I can think of but haven't been able to find anything to help. I'm not even real sure what it is I need to Google! Any help would be greatly appreciated!

3
  • 8
    The secret lies inside the PopulateDropdown() function. Post it too... Commented Aug 24, 2012 at 19:12
  • Can you expand the code you've shown? I'm wondering if the block of code shown is something you're including as a callback parm in a function or something. Commented Aug 24, 2012 at 19:19
  • Hi...I want to post the code but don't know how to do it. Commented Aug 27, 2012 at 16:38

1 Answer 1

1

This'd how you combine the 3 into a single function:

$(function () {
    PopulateDropdown('OwnerList');
    PopulateDropdown('ClientList');
    PopulateDropdown('AssignedToList');
});
Sign up to request clarification or add additional context in comments.

5 Comments

Is this what the OP was asking for?
Seems more likely to me that PopulateDropdown clears all three dropdowns then populates whichever one you pass in.
Well, this actually may be the right answer if the OP is using the OP code as a callback parm.
@mike: you're probably right. but unless the OP shows that chunk of code, no way to be sure.
You can call the $() function as many times as you want, it will just add onload handlers: jsfiddle.net/6dumD

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.