473,406 Members | 2,439 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,406 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 2877

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" ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.