Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Catching cursorkeys in IE

Reply
Thread Tools

Catching cursorkeys in IE

 
 
F. Da Costa
Guest
Posts: n/a
 
      12-14-2003
Hi,

The following snip works totally ok in a Gecko browser, for the 'normal keys as well as the cursorkeys.

<p>Key in the searchable 'thing':<br />
<input type="text" value="" id="txt1" onkeypress="var e= event; alert(e.keyCode);" />
</p>

In IE 5+ however the cursokeys do NOT register at all.
Insofar as I have been able to gather the keyCode property should be supported by IE (which is probably a
misundestanding from my side).
What *would* be the correct way to catch the cursorkeys?

TIA
Fermin DCG
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      12-14-2003


F. Da Costa wrote:

> The following snip works totally ok in a Gecko browser, for the 'normal
> keys as well as the cursorkeys.
>
> <p>Key in the searchable 'thing':<br />
> <input type="text" value="" id="txt1" onkeypress="var e= event;
> alert(e.keyCode);" />
> </p>
>
> In IE 5+ however the cursokeys do NOT register at all.
> Insofar as I have been able to gather the keyCode property should be
> supported by IE (which is probably a misundestanding from my side).
> What *would* be the correct way to catch the cursorkeys?


I think IE fires only keydown and keyup events for cursor keys.

--

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

 
Reply With Quote
 
 
 
 
F. Da Costa
Guest
Posts: n/a
 
      12-14-2003
F. Da Costa wrote:
> Hi,
>
> The following snip works totally ok in a Gecko browser, for the 'normal
> keys as well as the cursorkeys.
>
> <p>Key in the searchable 'thing':<br />
> <input type="text" value="" id="txt1" onkeypress="var e= event;
> alert(e.keyCode);" />
> </p>
>

MS does not like onKeyPress! Using onKeyDown seems to work ok (don't ask why).

> In IE 5+ however the cursokeys do NOT register at all.
> Insofar as I have been able to gather the keyCode property should be
> supported by IE (which is probably a misundestanding from my side).
> What *would* be the correct way to catch the cursorkeys?
>
> TIA
> Fermin DCG

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      12-14-2003
F. Da Costa wrote:

> The following snip works totally ok in a Gecko browser, for the 'normal keys as well as the cursorkeys.


RFC 2822, section 2.1.1, calls for a reasonable maximum of 78 characters
per line. Please set your automagic linebreak then to recommended 72 to
76 characters per line in order not to exceed that maximum when quoting
others or being quoted. I guess the preference can be set with Edit,
Preferences, Composition, Composing Messages, Wrap plain text messages
at [__] characters in Mozilla Thunderbird as it can in Mozilla MailNews.
For I know that Thunderbird is a comparably young project, if there is
no preference (RTFM!) you should consider to update your Thunderbird.

> <p>Key in the searchable 'thing':<br />
> <input type="text" value="" id="txt1" onkeypress="var e= event; alert(e.keyCode);" />
> </p>


In addition to what Martin wrote:

Do not declare a global variable in an event handler.
For general keyboard event handling, you would use

function handlerFunction(e)
{
var keyCode =
(e.which
? e.which
: (e.keyCode
? e.keyCode
: 0));

if (keyCode ...)
{
...
}
}

<... onwhatever="handlerFunction(event);" ...>


HTH

PointedEars
 
Reply With Quote
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      12-15-2003
Thomas 'PointedEars' Lahn <(E-Mail Removed)> writes:

> function handlerFunction(e)
> {
> var keyCode =
> (e.which
> ? e.which
> : (e.keyCode
> ? e.keyCode
> : 0));


FWIW, (foo ? foo : bar) can be written shorter as (foo || bar).
That means that your code above can be written as
var keyCode = e.which || e.keyCode || 0;

/L
--
Lasse Reichstein Nielsen - http://www.velocityreviews.com/forums/(E-Mail Removed)
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      12-15-2003
Lasse Reichstein Nielsen wrote:

> FWIW, (foo ? foo : bar) can be written shorter as (foo || bar).
> That means that your code above can be written as
> var keyCode = e.which || e.keyCode || 0;


n1, thx


\V/ PointedEars
 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      12-15-2003
JRS: In article <(E-Mail Removed)>, seen in
news:comp.lang.javascript, Thomas 'PointedEars' Lahn
<(E-Mail Removed)> posted at Mon, 15 Dec 2003 00:21:46 :-
>F. Da Costa wrote:
>
>> The following snip works totally ok in a Gecko browser, for the 'normal keys

>as well as the cursorkeys.
>
>RFC 2822, section 2.1.1, calls for a reasonable maximum of 78 characters
>per line. Please set your automagic linebreak then to recommended 72 to
>76 characters per line in order not to exceed that maximum when quoting
>others or being quoted.
> ...



That should not be done, except in a truly intelligent editor, if you
are likely to want to post long lines of HTML or of script (which you
did).

It is of *primary* importance that script, at least, should not be
artificially broken.

The need, therefore, with most systems, is to post with margins at least
as wide as the included code. Obviously, it is then a good thing to
write your HTML, and your script, within a reasonable margin of about 72
characters; and, if you cannot do so, you need to control the length of
lines in plain text by other means, such as by inserting breaks
manually.

TL is a Mussolini wannabe, but does not really understand the proper use
of News.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to catching loading exception? Bob ASP .Net 5 02-19-2005 07:07 AM
Catching Apache error with a Perl script PapaBear Perl 2 08-20-2003 12:56 PM
Catching events in web form fired by user control Nick Lewis ASP .Net 1 08-01-2003 12:01 PM
Re: catching exceptions from web user controls Marina ASP .Net 2 07-08-2003 04:48 PM
Catching an SelectedIndexChanged event from a DropDownList inside a DataGrid Dominic ASP .Net 2 07-04-2003 04:43 AM



Advertisments