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 2 2906 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("rea dy=true", 500);
// your processing here
}
}
--
S.C.
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("com pareCounts()", 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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();"
|
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 a device.
The definition of the table is as follows:
CREATE TABLE devicedata
(
device_id int NOT NULL REFERENCES devices(id), -- id in the device
|
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 object?
// get inputElement
alert("Some java script code");
inputElement.onkeyup = ????;
|
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 this
var oElmt = document.createElement("input");
:
|
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. The only problem is that I'd like
to implement an external event sink so that when the text
control loses focus, I can do ... well whatever I might
happen to want the event sink to do.
The code below will even sink the onblur event of the...
| |
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 populate a combo box with these names.
(this way, I can display all the EMPLOYEE_NAME values)
(2) In general, can I do additional processing on column values from
|
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 the
textbox or click somewhere else on the page. This isn't really ideal -
is there another event I can use which will fire immediately when a
user changes text in a textbox?
Chris
|
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 autopostback on,
the autopostback does not trigger. The autopostback will trigger if I
hit the enter key while in the textbox but not when I leave focus.
Here is the code for the textbox.
<asp:textbox class="required" AutoPostBack="True"...
|
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" onkeyup="javascript:calculate_stake();" >
<script type="javascript">
function calculate_stake()
{
//document.getElementById("potential_earnings_currency").innerHTML=
// document.createbet2.play_amount.value
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |