Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show "Loading..." in dropdown box

I'm running a database query to load a dropdownbox using jquery. Is there a way to display the words "Loading..." in the dropdownbox while the query is running?

Thanks.

like image 363
Tony Borf Avatar asked Jul 13 '09 17:07

Tony Borf


4 Answers

You can add temporary item to your dropdown list while the ajax is running:

$('#myDropDown').prepend($('<option></option>').html('Loading...'));
like image 158
algiecas Avatar answered Oct 22 '22 03:10

algiecas


Let's call your drop down 'userChoice', you can write code like

$(document).ready(
    function()
    {

        //Before calling your ajax method, clear the select drop down.
        //and add a loading option.
        $('#userChoice')
            .children()
            .remove()
            .end()
            .append('<option value="">Loading...</option>');

        $.ajax(

                    //Load the userChoice as usual in success handler of your ajax call. 
                    success : function() { //Load #userChoice } 
              );


    }
);
like image 25
SolutionYogi Avatar answered Oct 22 '22 03:10

SolutionYogi


If there's nothing in there to begin with, just make that your default HTML and you've eliminated half of your jQuery.

<select>
  <option>Loading...</option>
</select>

And when your query has finished, just replace the single option with your results.

like image 2
Sampson Avatar answered Oct 22 '22 05:10

Sampson


add this before ajax post

$('#myDropDown').empty();
$('#myDropDown').append($('<option></option>').html('Loading...'));

then again on success dynamically append dropdown

$('#myDropDown').empty();
$('#myDropDown').append($('<option></option>').val("").html("Select"));
for (var i = 0; i < array.length; i++) {
                $('#myDropDown').append($('<option></option>').val(array[i].selectedvalue).html(array[i].selectedtext));
            }
like image 1
Atiq Baqi Avatar answered Oct 22 '22 03:10

Atiq Baqi