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.
 

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

Javascript shipping countdown timer code help 9
Please Help? 0
Arduino Code Please Help 0
Javascript shipping countdown issue 10
Code help please 4
Help please 8
Need help again please 19
Please help 7

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top