473,625 Members | 3,064 Online
Bytes | Software Development & Data Engineering Community
+ 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.preventDefau lt)
e.preventDefaul t();
else
window.event.re turnValue=false ;

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

TIA

Jonas
Jul 23 '05 #1
4 1911


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*****@bredba nd.net> wrote in message
news:7a******** *************** **@posting.goog le.com...
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.preventDefau lt)
e.preventDefaul t();
else
window.event.re turnValue=false ;

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

TIA

Jonas


How are you invoking your function?

Is it like the following?

<input type="text" onkeypress="ret urn KeyDownHandler( )">
Jul 23 '05 #3
"McKirahan" <Ne**@McKirahan .com> wrote in message news:<oH3id.562 917$8_6.533088@ attbi_s04>...
"Jonas" <fu*****@bredba nd.net> wrote in message
news:7a******** *************** **@posting.goog le.com...
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.preventDefau lt)
e.preventDefaul t();
else
window.event.re turnValue=false ;

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

TIA

Jonas


How are you invoking your function?

Is it like the following?

<input type="text" onkeypress="ret urn KeyDownHandler( )">


Hi!

I invoke it like this:

<input type="text" onkeypress="Key DownHandler(eve nt);">

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

Brgds

Jonas
Jul 23 '05 #4
"Jonas" <fu*****@bredba nd.net> wrote in message
news:7a******** *************** **@posting.goog le.com...
"McKirahan" <Ne**@McKirahan .com> wrote in message

news:<oH3id.562 917$8_6.533088@ attbi_s04>...
"Jonas" <fu*****@bredba nd.net> wrote in message
news:7a******** *************** **@posting.goog le.com...
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.preventDefau lt)
e.preventDefaul t();
else
window.event.re turnValue=false ;

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

TIA

Jonas


How are you invoking your function?

Is it like the following?

<input type="text" onkeypress="ret urn KeyDownHandler( )">


Hi!

I invoke it like this:

<input type="text" onkeypress="Key DownHandler(eve nt);">

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
9768
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) ? window.event : "") ...
7
4094
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 accompanied by an alternative OnKeyPress event. The guidelines are very vague and I am not sure what this means. I have used the following piece of JavaScript inside the cell of a table: onclick="window.open('http://www.etc') Do I need to...
2
11116
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 tutorial/guide?
4
10543
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 using "onkeypress=myKeypressHandler()" but, beyond that, I'm stuck. I forget how to detect what key was pressed or how to "null it out". I'm using IE6 and users will be IE5.0 upward ONLY (trust me on this, suffice to say it's not a website but...
5
3757
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 processing on certain key/mouse events 3) If key/mouse events interrupt processing, the events should not be discarded since they need to be handled but AFTER the current processing is complete
2
4172
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 void OnKeyPress(System.Object sender, System.Windows.Forms.KeyPressEventArgs e) { /* Do Nothing */ } } public class Class1 : Main
2
2272
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 where you can type "r" anywhere on the page while viewing a message and it will open a reply box, but if you type an "r" while entering text into a form, it doesn't do this. My question is how to do this most efficiently.
3
5160
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. The "<body.." tag in each frame includes an "onKeyPress" handler to catch and act on key presses. And if I focus the window by clicking on the content of one of the documents, keystrokes are sent to the handler on its "<body..." tag.
8
4260
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 raise an event how do I create an handler to catch these raised events. //Tony
0
8259
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8696
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8358
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8502
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6119
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5571
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4090
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4195
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.