473,325 Members | 2,771 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,325 software developers and data experts.

Help Capturing an onkeyup event

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 = ????;

I know how to assign generic functions. This works:

inputElement.onkeyup = function() { alert("hello"); };

But how in the world do I assign a function that captures the "event"
object? I want something like:

inputElement.onkeyup = function(event) { processEvent(event) };

But that doesn't work right. Any ideas?
Jul 23 '05 #1
3 8816


Trent wrote:

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 = ????;

I know how to assign generic functions. This works:

inputElement.onkeyup = function() { alert("hello"); };

But how in the world do I assign a function that captures the "event"
object? I want something like:

inputElement.onkeyup = function(event) { processEvent(event) };

But that doesn't work right. Any ideas?


That last attempt should work with Mozilla/Netscape however the problem
is that IE has a global variable window.event that your event parameter
shadows so you need
inputElement.onkeyup = function (evt) {
if (!evt) {
evt = window.event;
}
// now use evt e.g.
alert(evt.keyCode);
};
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2
Trent wrote:
Hi. I know the basic way to assign event handlers:

<input onKeyUp="processEvent(event)" />


No. You must decide if you want to use HTML

<!-- attribute name case does not matter, no trailing / -->
<iNpUt onKeyUp="processEvent(event)">

or XHTML

<!-- element and attribute names must be lowercased,
trailing / (empty content model) -->
<input onkeyup="processEvent(event)"/>
PointedEars
Jul 23 '05 #3
Does it work well finally? Today I need to implement the onkeyup event
but I found it doesn't work consistently. usually, the first few stroke
does not trigger the event, till I switch to another field and back to
this field. Then, the event can be fired for every keystroke. Any
idea?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #4

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();"
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: john.lum | last post by:
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...
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" ...
3
by: Brent | last post by:
The code below correctly sets an iframe to be editable, and then tries to attach an "onkeyup" event to the iframe. Instead of doing that, however, it generates a cryptic "Object required" error in...
0
by: user1980 | last post by:
How do I write a custom validator for the onkeyup event. my scenario is two textboxes and if one of them is filled the other has to be filled to. if not both need not be filled(so, onkeyup event...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.