javascript help please

R

rodchar

hey all,
i have a key up javascript function where i want half the function to run
and then wait about 2 seconds, but if within that 2 seconds another key up
event has a occurred, i need it to cancel the initial call to the function.

can someone please show me if this can be done.

thanks,
rodchar
 
C

cfps.Christian

You can use a global timer variable.

var tim;
function onKeyDown()
{
if (tim != null)
clearTimeout(tim);
tim = setTimeout('TimerUp()', 2000);
//do key work here
}
function TimerUp()
{
//do timer work here
}
 
C

Cowboy \(Gregory A. Beamer\)

You have an answer, but I suggest you consider the problem domain before
solving in this manner. Most likely, you are either a) wanting to allow for
corrections or b) wanting to wait until the entire string is entered before
processing.

If a, your method might be the best, depending on what you are doing. If b,
you can process the portion that fits the keystroke and then capture the
blur event for the control to do complete processing. This will help you
avoid the wait two seconds.

I know nothing of your app, but I did a heavy JavaScript app years ago for
key entry (replace a windows app). If I would have waited two seconds, I
would have been hosed. Your app is, hopefully, completely different.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
 

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

Similar Threads


Top