views:

264

answers:

1

i have the following code where i getJSON after i click on a select box. Sometimes it takes a long time and the users are clicking on the dropdown again during the server side processing.

Is there anyway to disable the dropdown during the server side call and reenabled it after the processing is complete.

here is my code

 <script type="text/javascript">
        $(document).ready(function() {

            $('#userDropdown').change(function() {
                if (this.selectedIndex != 0) {
                    var URL = "/Users/GetUserJson/" + this.value;

                    $.getJSON(URL, function(data) {

                         var userID = data.UserId;
                         var userColor = data.UserColor;

                         . . . .
A: 

Nerdling suggested that you hide the select, but I'd rather just disable it, just like you said yourself:

$('#userDropdown').change(function() {
    // Assign the select in a variable
    var sel = $(this);
    if (this.selectedIndex != 0) {
        // Disable it
        sel.attr('disabled', 'disabled')
        var URL = "/Users/GetUserJson/" + this.value;

        $.getJSON(URL, function(data) {

            var userID = data.UserId;
            var userColor = data.UserColor;

            // Enable it
            sel.removeAttr('disabled');

            ...
Tatu Ulmanen
hmm . .in your code above disabling it works but it never gets reenabled . .
ooo
in firebug it gives as error saying "sel.removeattr is not a function"
ooo
it was just a casing issue . . i fixed your answer and marked it accepted
ooo
Yea, sorry about that :)
Tatu Ulmanen