Connecting Tech Pros Worldwide Help | Site Map

Help Capturing an onkeyup event

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 10:27 AM
Trent
Guest
 
Posts: n/a
Default 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?

  #2  
Old July 23rd, 2005, 10:27 AM
Martin Honnen
Guest
 
Posts: n/a
Default Re: Help Capturing an onkeyup event



Trent wrote:

[color=blue]
> 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?[/color]

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/

  #3  
Old July 23rd, 2005, 10:40 AM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default Re: Help Capturing an onkeyup event

Trent wrote:
[color=blue]
> Hi. I know the basic way to assign event handlers:
>
> <input onKeyUp="processEvent(event)" />[/color]

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
  #4  
Old July 23rd, 2005, 11:12 AM
Evan Wong
Guest
 
Posts: n/a
Default Re: Help Capturing an onkeyup event

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!
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.