Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Need advice for acting on only the last onkeyup event in a series

Reply
Thread Tools

Need advice for acting on only the last onkeyup event in a series

 
 
john.lum@gmail.com
Guest
Posts: n/a
 
      01-30-2006
My overall objective is to create something akin to Google Suggest,
where a query is done in response to changes in a text field presented
to the user.

I've got things working using the onkeyup event and some AJAX
techniques, but I am troubled by one thing: the more characters that
are entered, the slower the interface is to settle down, because a
discrete lookup is done each time the field changes by a single
character.

What I'd prefer is to define a time window (say, n = 500ms) and alter
my code so that it ignores the onkeyup events until at least n ms has
elpased since the last event. I've tried various approaches using
setTimeout, and I'm unable to come up with a working solution to what
seems like a straightforward problem. Various Googlings have not given
me any love, which makes me suspect I'm searching for the wrong things.

Any advice on the best way to achieve this "ignore onkeyup until at
least n ms has elapsed since the last field change" would be greatly
appreciated. Alternative approaches are also welcome.

Thanks,
John

 
Reply With Quote
 
 
 
 
Stephen Chalmers
Guest
Posts: n/a
 
      01-31-2006

wrote:
> My overall objective is to create something akin to Google Suggest,
> where a query is done in response to changes in a text field presented
> to the user.
>
> I've got things working using the onkeyup event and some AJAX
> techniques, but I am troubled by one thing: the more characters that
> are entered, the slower the interface is to settle down, because a
> discrete lookup is done each time the field changes by a single
> character.
>
> What I'd prefer is to define a time window (say, n = 500ms) and alter
> my code so that it ignores the onkeyup events until at least n ms has
> elpased since the last event. I've tried various approaches using
> setTimeout, and I'm unable to come up with a working solution to what
> seems like a straightforward problem. Various Googlings have not given
> me any love, which makes me suspect I'm searching for the wrong things.
>
> Any advice on the best way to achieve this "ignore onkeyup until at
> least n ms has elapsed since the last field change" would be greatly
> appreciated. Alternative approaches are also welcome.
>
> Thanks,
> John


Did you try something like this?:

var ready=true;

function readText() //keyup handler
{
if(ready)
{
ready=false;
setTimeout("ready=true", 500);

// your processing here

}
}

--
S.C.

 
Reply With Quote
 
 
 
 
john.lum@gmail.com
Guest
Posts: n/a
 
      01-31-2006
Thanks much for the suggestion. Your approach didn't quite work for
me; it did not achieve the desired result of deferring response action
until the "final" keypress prior to a delay of at least 500 ms.

However, I did get things working with a modified version that uses
global variables:

//--------------
var keyCount = 0;
var timeoutCount = 0;

function handleKeyUp() // keyup handler
{
keyCount++;
setTimeout("compareCounts()", 350);
}

function compareCounts()
{
timeoutCount++;
if (keyCount == timeoutCount)
{
// my processing goes here
}
}
//--------------

There may be better/non-global-variable techniques involving passing
function references to the setTimeout function, but I will settle for
quick and dirty.

Thanks,
John

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autopostback and onkeyup event issue Brad ASP .Net 3 04-20-2006 06:38 PM
OnKeyUp event does not work Evan Wong Javascript 2 05-27-2004 06:26 AM
Help Capturing an onkeyup event Trent Javascript 3 05-26-2004 12:46 PM
Modifying a onkeyup event to ignore Tab keypress Matthew Javascript 5 02-10-2004 05:49 PM
What is the difference between A Series, G Series and S series of Canon Cameras zxcvar Digital Photography 3 09-09-2003 01:30 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57