Pausing in javascript

D

Doogie

Hi,
I am trying to modify an ASP 3.0 app and am running into an issue.
Essentially the part that I'm modifying queries the database and
returns a record count. This part is done using
"Microsoft.XMLHTTP".

The call to the database has a very slight delay (not sure if it's
cause of our code or the Microsoft object). But the app does not wait
for the data call to return before processing the rest of the
functionality in the method. So my check on the record count is
always 0, even though sometimes there are records in there (because
the variable I assign the record count to does not get set before the
check on that variable is done).

I have been looking at ways to pause apps in java and came across
setInterval and clearInterval. But that is not working like I'd
expect. Here's what I'd like to do:

1. Call my db method (where the record count variable is assigned).
2. Use setInterval to wait until that record count variable is
actually set.
3. Proceed with my code.

I may not understand how the set and clear interval methods work so am
posting some of the code. This code has two problems:
1. It does not clear out the interval like I'd expect - it's as if
the interval value is different each time (which make sense but I'm
not sure how to set it up to perform that work I put in the check
detail count method otherwise):
2. It runs the CompleteInvoice piece without waiting on the
setInterval piece to stop. So I'm still in the same boat as before.

Any help would be greatly appreciated!

function CallComplete()
{
var numberOfInvoiceRows =
spnTableDisplay.firstChild.tBodies[0].rows.length

for(var index = 0; index < numberOfInvoiceRows; index++)
{
g_TotalDetailRows = -1 --THIS IS MY RECORD COUNT VARIABLE
var rowObj = spnTableDisplay.firstChild.tBodies[0].rows[index]
GetDetails(rowObj) --INSIDE THIS METHOD THE RECORD COUNT
VARIABLE IS SET
vendorType =
rowObj.cells[2].children("txt_VENDOR_TYPE_AN").value
interval = setInterval("CheckDetailCount()", 1000)
}

CompleteInvoice()
}

function CheckDetailCount()
{
if (g_TotalDetailRows != -1)
{
clearInterval(interval)
if (g_TotalDetailRows < 1)
{
alert("The invoice row for vendor type '" + vendorType + "'
does not have a detail row.")
return
}
}
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top