473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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

Jan 30 '06 #1
2 2873

jo******@gmail.com 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.

Jan 31 '06 #2
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

Jan 31 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Matthew | last post by:
Is there anyway to tweak this to ignore the function() only if the Tab key is pressed? onkeydown="javascript:function();"
9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
3
by: Trent | last post by:
Hi. I know the basic way to assign event handlers: <input onKeyUp="processEvent(event)" /> But how do I assign a function to the onKeyUp event in *javascript* that can access the event...
2
by: Evan Wong | last post by:
I have problem to get onkeyup event. If we put the event in HTML statement like - "<input name=field1 size=16 onkeyup="javascript:function1();>" it works. If we put in JavaScript code like...
2
by: | last post by:
I have the some HTML and JavaScript code that implements a type-ahead capability for a text input control linked to a select control (see end of message). The type-ahead functionality works well....
3
by: ssb | last post by:
Hello, This may be very elementary, but, need help because I am new to access programming. (1) Say, I have a column EMPLOYEE_NAME. How do I fetch (maybe, cursor ?) the values one by one and...
1
by: Chris Ashley | last post by:
I'm using the javascript onchange event in a few places but it's behaviour isn't as expected. In order for this event to fire after changing text in a textbox, the user needs to either tab out of...
3
by: Brad | last post by:
The first text on my form is a numeric field. I have a javascript that runs on this field for onkeyup (validate the key strokes and modifies fields on the screen) but when I do this and have the...
1
by: manojsharma | last post by:
hey can anybody tell me y my onkeyup event is not working in firefox.. it is working fine in IE... code <input type="text" name="oddteam" size="1" value="1" ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.