[Javascript] Re: Re: Is this right Javascript?

Rodney Myers rodney at aflyingstart.net
Wed Apr 9 12:21:02 CDT 2003


Test file:

<html><head></head>
<body>
<form name="Test1">
<textarea onkeydown="alert('hello')"></textarea>
</form>
</body></html>

This did NOT work in these browsers under WIndows XP

Netscape 4.6
Netscape 7.02
Explorer 6.0
Opera 7

<textarea onClick="alert('hello')"> worked.
<textarea onKeyPress="alert('hello')"> did not.

Since I am unfamiliar with this onkeydown event I suspect I have missed 
something vital.
If PPK says it works I believe it, but I need to know "how?"

onKeyDown seems to be the proper capitalisation, but it made no difference.


Furthermore, this file taken verbatim from "Pure Javascript" by Wyke et 
al (2nd Ed) did not work either.
in Explorer it gave the error 'Event' is undefined.

(It is a good book, but the examples on the CD were poorly proofread imho)

<html>
<head>

<script type="text/javascript" language="JavaScript1.2">
<!--

// Tell the browser you want to intercept ALL key press events
// on the page and then define a function to handle them.
document.captureEvents(Event.KEYPRESS);
document.onKeyPress = myKeyPressHandler;

// Define the myKeyPressHandler function to handle
// key press events.
function myKeyPressHandler(e){
  alert("A key press event took place within the document!");
}

// -->
</script>
</head>
<body>
Anytime you press a key within this document, you will
get a message alerting you that a KeyPress event has taken place.
</body>

Cliff Wootton in JavaScript Programmers Reference marks onkeydown event 
for textarea with warning and a "-" in the DOM column of the browser 
compatibility table for the textarea
Flanagan ("Rhino" 3rd ed) notes that onKeyDown is not yet part of DOM 
standard. This may have changed. (and on relflection  I would be 
embarrassed if asked to explain what that means, esp in practice)

Puzzled.....

Rodney

Peter-Paul Koch wrote:

>
>
>> >   Third, 'onkeydown' is undefined for normal JavaScript (although 
>> it may  have
>> >   some bizarre other-worldly existence in M$oft's bastardized 
>> JScript).
>> >
>> >   I suspect the event you were attempting to intercept was 
>> 'onclick',  which
>> >   IS defined, and actually makes sense for a checkbox.
>>
>> I know it's cool to bash Microsoft whenever the chance arises, but a 
>> simple sample would show you this is not some "bastardized" 
>> javascript unless NN is now bastardizing it too:
>>
>> <form name="Test1">
>>
>>
>> <textarea onkeydown="alert('hello')"></textarea>
>>
>> </form>
>>
>>
>> Put that on a page and view it in NN and you'll see it works fine, as 
>> long as you're not using the ultimate in bastardized browsers - NN4.7
>
>
> It even works in NN4.7 The Key events have been around, and well 
> supported, since the Version 4 browsers.






More information about the Javascript mailing list