Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript onkeyXXXX function and Netscape 4.75

Status
Not open for further replies.

wahoo02

Programmer
Sep 15, 2003
5
0
0
US
I am having a problem getting JavaScript onkeyXXX events to work in Netscape 4.75. And yes, unfortunately, I have to support Netscape 4.75. Below is some sample code from another forum that exactly describes the problem that I am having.

-------------------------------------------------
From:
In Netscape 4.75, onkeypress, onkeyup and onkeydown fail on text boxes within a table. If the text boxes are not in a table, the onkeyxxx works.

This one fails:
<html>
<head>
<title>Test Keypress</title>
</head>
<body>
<form>
<table width="70%" border="1"><tr><td>
<b>CkKeyUp:</b></td><td>
<input type="text" name="temp" size="10" onkeyup="alert('keyup')"></td></tr>
<tr><td>
<b>CkKeyDn:</b></td><td>
<input type="text" name="temp" size="10" onkeydown="alert('keydown')"></td></tr>
<tr><td>
<b>CkKeyPress:</b></td><td>
<input type="text" name="temp" size="10" onkeypress="alert('keypress')"></td></tr>
</table>
</form>
</body>
</html>

but this one works:
<html>
<head>
<title>Test Keypress</title>
</head>
<body>
<form>
<b>CkKeyUp:</b></td><td>
<input type="text" name="temp" size="10" onkeyup="alert('keyup')"><br>
<b>CkKeyDn:</b>
<input type="text" name="temp" size="10" onkeydown="alert('keydown')"><br>
<b>CkKeyPress:</b>
<input type="text" name="temp" size="10" onkeypress="alert('keypress')">
</form>
</body>
</html>

And even weirder, on rare occasions, the failing example will work as well. That is, if you keep reloading the failing example, once in a while (about 1 out of 10 times), it will work.

Can anyone tell me if there is any way to get the onkeyxxx triggers within a table to work reliably in NS 4.75? (I'm using the table merely as a layout device).

Thanks for any help/advice. Suggestions or documentation explaining this behavior are welcome.
 

Have you tried explicity capturing the events at the window level?... Something like this:

Code:
<script language="JavaScript1.2">
   function nnCaptureKeys(e) {
      // your code here
      alert('Capturing!');
   }
   window.captureEvents(Event.KEYPRESS);
   window.onKeyPress = nnCaptureKeys;
</script>

It's been a long while since I've used the "language=" syntax or done any coding for NN4.x... but give it a whirl anyway!

Hope this helps,
Dan

 
That code does work, however I need to be able to capture onKey events within a table and to be able to distinguish which text box is causing the event to fire. The capturing of window events is too broad. The real issue is trying to capture text box events from inside a table, as you can see in the example above it is able to easily capture events from text boxes just on the page.

I suppose I could put all my functionality for all of the onKey events at the top but that would be poor performing code since each individual textbox’s code would be executed whenever an onKey event was detected in the window. It would be best if there were some way to get the events to fire individually for each text box, from within a table.

A demonstration using the example code above would be greatly appreciated.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top