views:

62

answers:

1

Hello,

I have a very long list of items for a dropdownlist. As the list is very long, I would like to only show the items in the list if the user actually clicks on the dropdownlist to expand it. I found various tutorials on how to use AJAX with cascading dropdownlists but none explaining if it is possible to have just one dropdownlist which gets populated with AJAX when the user expands it.

Are there any extenders coming with the AJAX toolkit that I missed? What would be the best way of achieving this?

Thanks, Ben

+1  A: 

What I would do is this:

Have one empty item in the list. When the dropdownlist receives focus then you change that one item to say Loading or something like that. Then you make the ajax call you want.

Once it completes you unbind the focus event from the dropdown so you don't reload on subsequent focus events.

Seems like it wouldn't be too difficult to do something like this.

I'll see if I can whip something up on jsfiddle if you need help.

EDIT: By the way to your question about extenders I don't know anything about that.

EDIT 2: You could try something like this:

$(document).ready(
    function()
    {
       $("#theSelect").bind("focus", function()
                            {
                                $("option:first", this).html("Loading...");
                                setTimeout(AjaxSuccessCall, 2000);
                            });
    });

function AjaxSuccessCall(data)
{
    var select = $("#theSelect");
    select.unbind("focus");
    select.children("option").remove();
}
spinon
Hi spinon, thanks for your reply. Do you know of any tutorials which would use such an approach? I am just starting with the whole AJAX thing so not quite sure what to look for.
b3n
I added an example.
spinon
Thanks for the example spinon, ill give it a try. Cheers.
b3n
Inside the focus event I have the settimeout call. That was just a stub for where you would put your AJAX call. Just wanted to make sure I cleared that up.
spinon