views:

21

answers:

1

Hi,

I have a website with is made in classic asp. On one page there are 5 textboxes and 5 labels. When users type some value in the textbox then using javascript (added on Onchange event) another asp page is called which done some calculations, fetches some database values based on the value typed and return the result to caller page to be displayed in the corresponding label. Same Page is called for all the textboxes for fetching result. My problem is if user types at normal speed and move to other textbox(using tab) at a normal speed the second page is called properly and result displayed properly in labels, but if the user type very fast then the request for the value of one textbox is not completed and other is send and as a result there is no result value coming for first one. Is there is any way to handle this.

Thanks

A: 

If you don't want to refactor the whole thing to use XHRequests, there's a simple solution. Have a "request in progress" flag that is checked in your onchange event. If a request is in progress, queue the current action. In the result display code, check the queue and execute the next action, if any. If there are no remaining actions, reset the flag.

Here's a basic outline in code:

var requestInProgress = false;
var pendingActions = []; 

function OnChangeHandler(onChangeFunction) {
    if(requestInProgress) {
        pendingActions.push(onChangeFunction);
    }
    else {
        requestInProgress = true;
        onChangeFunction();
    }    
}

function ResponseHandler()
{
    //Your regular response handling code
    if(pendingActions.length > 0) {
        var nextFunction = pendingActions.shift();
        nextFunction();
    }
    else {
        requestInProgress = false;
    }
}

I'm no JS expert, so I'm sure that this could be cleaned up a little bit, but it should handle overlapping events just fine.

jball
Thanks for your reply. I think this will solve my problem but i would like to know more about other way also.(refactor the whole thing to use XHRequests). What i have to do use XHRequests.
Saurabh
There are many guides findable via [Google](http://www.google.com/search?q=xhr+classic+asp) (eg, [Mikesdotnetting](http://www.mikesdotnetting.com/Article/98/Ajax-with-Classic-ASP-using-jQuery)), and SO has a [number of questions](http://stackoverflow.com/questions/tagged/asp-classic+json) about it as well. If you run into a problem doing the conversion, post a new question here containing your code and problems, and you'll probably get some help.
jball