473,467 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Preventing onkeypress events in Netscape 7 for Mac fail

Hi!

I have a web page where I want to intercept keypress events in an INPUT-tag
and check if it is the Enter key, which calls another function that executes
a search. My code runs on Netscape 7 for Windows, IE 6 for Windows and IE5.1
for Mac, but not on Netscape 7 for Mac. When I press the Enter key, the
event gets caught but it does not get prevented and the search is never
executed.

The code looks like this:

function KeyDownHandler(e)
{
// if not Netscape, get IE event
if ( !e )
e = window.event;
if ( !e )
return true;

// Get valid ascii character code
var key = typeof e.keyCode != 'undefined' ? e.keyCode : e.charCode;
// process only the Enter key
if (key == 13)
{
// cancel the default submit
if (e.preventDefault)
e.preventDefault();
else
window.event.returnValue=false;

// submit the form by programmatically searching
search();
return false;
}
else
{
return true;
}
}

TIA

Jonas
Jul 23 '05 #1
4 1904


Jonas wrote:
I have a web page where I want to intercept keypress events in an INPUT-tag
and check if it is the Enter key, which calls another function that executes
a search. My code runs on Netscape 7 for Windows, IE 6 for Windows and IE5.1
for Mac, but not on Netscape 7 for Mac. When I press the Enter key, the
event gets caught but it does not get prevented and the search is never
executed.

The code looks like this:

function KeyDownHandler(e)


You can only cancel keys with Netscape/Mozilla for the keypress event. I
don't know how you use that function named KeyDownHandler but the name
suggests you are using it as the onkeydown handler while you should use
it as the onkeypress event handler.
Other than that I see nothing wrong, you might want to download a recent
Mozilla build from http://www.mozilla.org/ and check on the Mac, if the
problem persists you can file a bug report on https://bugzilla.mozilla.org/.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
"Jonas" <fu*****@bredband.net> wrote in message
news:7a*************************@posting.google.co m...
Hi!

I have a web page where I want to intercept keypress events in an INPUT-tag and check if it is the Enter key, which calls another function that executes a search. My code runs on Netscape 7 for Windows, IE 6 for Windows and IE5.1 for Mac, but not on Netscape 7 for Mac. When I press the Enter key, the
event gets caught but it does not get prevented and the search is never
executed.

The code looks like this:

function KeyDownHandler(e)
{
// if not Netscape, get IE event
if ( !e )
e = window.event;
if ( !e )
return true;

// Get valid ascii character code
var key = typeof e.keyCode != 'undefined' ? e.keyCode : e.charCode;
// process only the Enter key
if (key == 13)
{
// cancel the default submit
if (e.preventDefault)
e.preventDefault();
else
window.event.returnValue=false;

// submit the form by programmatically searching
search();
return false;
}
else
{
return true;
}
}

TIA

Jonas


How are you invoking your function?

Is it like the following?

<input type="text" onkeypress="return KeyDownHandler()">
Jul 23 '05 #3
"McKirahan" <Ne**@McKirahan.com> wrote in message news:<oH3id.562917$8_6.533088@attbi_s04>...
"Jonas" <fu*****@bredband.net> wrote in message
news:7a*************************@posting.google.co m...
Hi!

I have a web page where I want to intercept keypress events in an

INPUT-tag
and check if it is the Enter key, which calls another function that

executes
a search. My code runs on Netscape 7 for Windows, IE 6 for Windows and

IE5.1
for Mac, but not on Netscape 7 for Mac. When I press the Enter key, the
event gets caught but it does not get prevented and the search is never
executed.

The code looks like this:

function KeyDownHandler(e)
{
// if not Netscape, get IE event
if ( !e )
e = window.event;
if ( !e )
return true;

// Get valid ascii character code
var key = typeof e.keyCode != 'undefined' ? e.keyCode : e.charCode;
// process only the Enter key
if (key == 13)
{
// cancel the default submit
if (e.preventDefault)
e.preventDefault();
else
window.event.returnValue=false;

// submit the form by programmatically searching
search();
return false;
}
else
{
return true;
}
}

TIA

Jonas


How are you invoking your function?

Is it like the following?

<input type="text" onkeypress="return KeyDownHandler()">


Hi!

I invoke it like this:

<input type="text" onkeypress="KeyDownHandler(event);">

Could it be the missing return statement that does the trick?

Brgds

Jonas
Jul 23 '05 #4
"Jonas" <fu*****@bredband.net> wrote in message
news:7a*************************@posting.google.co m...
"McKirahan" <Ne**@McKirahan.com> wrote in message

news:<oH3id.562917$8_6.533088@attbi_s04>...
"Jonas" <fu*****@bredband.net> wrote in message
news:7a*************************@posting.google.co m...
Hi!

I have a web page where I want to intercept keypress events in an

INPUT-tag
and check if it is the Enter key, which calls another function that

executes
a search. My code runs on Netscape 7 for Windows, IE 6 for Windows and

IE5.1
for Mac, but not on Netscape 7 for Mac. When I press the Enter key, the event gets caught but it does not get prevented and the search is never executed.

The code looks like this:

function KeyDownHandler(e)
{
// if not Netscape, get IE event
if ( !e )
e = window.event;
if ( !e )
return true;

// Get valid ascii character code
var key = typeof e.keyCode != 'undefined' ? e.keyCode : e.charCode; // process only the Enter key
if (key == 13)
{
// cancel the default submit
if (e.preventDefault)
e.preventDefault();
else
window.event.returnValue=false;

// submit the form by programmatically searching
search();
return false;
}
else
{
return true;
}
}

TIA

Jonas


How are you invoking your function?

Is it like the following?

<input type="text" onkeypress="return KeyDownHandler()">


Hi!

I invoke it like this:

<input type="text" onkeypress="KeyDownHandler(event);">

Could it be the missing return statement that does the trick?

Brgds

Jonas


Yes. The "return " negates the Enter key when the function returns "false".
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Fred Brown | last post by:
Hi, I want to cancel a certain key in JavaScript. To do so, I catch the event in OnKeyPress and cancel the default: <head> .... function f(evt) { var evt = (evt) ? evt : ((window.event) ?...
7
by: Kev | last post by:
I need to make some specific alterations to some JavaScript in webpages in order to comply with government guidelines on accessibility. Apparently, whenever the OnClick event is used, it must be...
2
by: Hasan Ammar | last post by:
Is it possible to set up hotkeys using onkeypress? I know it can be done with the usual alphanumeric keys, but what about function keys? or using ctrl/alt combinations? Does anybody have a...
4
by: owen | last post by:
I have an <input> box and i want to disable the apostrophe ( ' ) key, so when you press it, no character appears in the input box. All other keys should work ok. I can trap the keypress event...
5
by: Bill Henning | last post by:
Does anyone know a good method of preventing keyboard and mouse events from interrupting processing? My situation is: 1) I need to track and handle all key and mouse events 2) I need to perform...
2
by: ~toki | last post by:
How can i take the control of the key events in Class2 ? This is the code snipped that i'd tried (after try some others): public class Main : System.Windows.Forms.Form { protected virtual...
2
by: jbigham | last post by:
Hello, I'd like to capture key events using javascript, but don't want to process such events when the user is typing into an input box or into a textarea. As an example, gmail has a feature...
3
by: Robert Inder | last post by:
I am struggling to catch kestrokes within an Internet Explorer 6 window. My window happens to be displaying three frames, though I suspect a similar problem would arise with a single document. ...
8
by: Tony Johansson | last post by:
Hello! I wonder can somebody explain when is it suitable to use these methods OnKeyUp, OnKeyDown and OnKeyPress because these raise an event. These are located in class UserControl. If these...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.