473,778 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript Cancel OnKeyPress prob on Safari

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 : "")
...
evt.returnValue = false; // IE
evt.preventDefa ult(); // dom 2 (also tried without this here)
return false; // netscape
}
....
<body>
....
<TEXTAREA Name=demoTextar ea ROWS=10 COLS=50 OnKeyPress="f(e vent)">
</TEXTAREA>

IE works fine.
Safari will not cancel the key.
I also checked to see if the textArea value already had received the
key before this handler. It had not.

Any ideas?

Thanks in advance,
Fred Brown
Jul 20 '05 #1
5 9779
fr***@inter.net .il (Fred Brown) writes:

I want to cancel a certain key in JavaScript.


Why?

I really hate it when folks use JavaScript to screw up
what I expect my browser to do.

I really can't think of a valid reason for you to be able to
do this. Just don't.
--
Plain Bread alone for e-mail, thanks. The rest gets trashed.
No HTML in E-Mail! -- http://www.expita.com/nomime.html
Are you posting responses that are easy for others to follow?
http://www.greenend.org.uk/rjk/2000/06/14/quoting
Jul 20 '05 #2
Br***********@f ractious.net wrote in message news:<yo******* ******@panix2.p anix.com>...
fr***@inter.net .il (Fred Brown) writes:

I want to cancel a certain key in JavaScript.
Why?

I did want to waste the forum's bandwidth with unnecessary details of
my app,
but in short, I am not actually just canceling the key, I am replacing
the
inputted keys with other keys. This makes sense in my app. It is the
reason that this textarea exists. My problem is that both the
replaced key and the original one end up in the textarea on Safari.
Does anybody know how to achieve this replacement?

I really hate it when folks use JavaScript to screw up
what I expect my browser to do.

I really can't think of a valid reason for you to be able to
do this. Just don't.

Jul 20 '05 #3
I can't remember the exact details but I seem to recall having problems
trapping keys - esp. the tab key - with onkeypress.

My solution was to look at onkeydown instead.

I can think of lots of reasons why you'd want to do this, by the way.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4
Peter,
I checked if I could cancel the onKeyDown on Safari and I could not.
I am no JavaScript expert but I think that onKeyPress is better for me
because it has already translated from virtual key to unicode. Also,
I believe if you hold down a key, you will get many onKeyPress events
for each
char that is processed but only one keyDown. I think you are right
though
that keyPress does not get called for all keys - I saw that it did not
get called on IE for a backspace (which makes sense since I assume
there is no
unicode defined for keys like a backspace.)

Thanks anyhow,
Fred Brown

Peter Hurford <pe***********@ microcrest.com> wrote in message news:<3f******* *************** *@news.frii.net >...
I can't remember the exact details but I seem to recall having problems
trapping keys - esp. the tab key - with onkeypress.

My solution was to look at onkeydown instead.

I can think of lots of reasons why you'd want to do this, by the way.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 20 '05 #5
Hi Fred,

Did you ever find a solution for this? I am now encountering the same
problem. We want to cancel non-numeric characters and have found a way to
do it that is supported by both IE6 and NS7 - onKeyPress event with a
handler that returns false (or sets event.returnVal ) if not numeric. Now
I'm trying to get it to work with Safari and it just won't. The onKeyPress
event fires, the handler is called, returns false appropriately, but doesn't
cancel the key. Since it has a window.event like IE, I tried setting
returnVal to false - nada. I tried setting event.keyCode to something
else - nada. I tried overriding the value of the object - nada.

Anyone have any ideas? Your help is greatly appreciated!

Julia Allen
ju********@delt ek.com
"Fred Brown" <fr***@inter.ne t.il> wrote in message
news:45******** *************** ***@posting.goo gle.com...
Peter,
I checked if I could cancel the onKeyDown on Safari and I could not.
I am no JavaScript expert but I think that onKeyPress is better for me
because it has already translated from virtual key to unicode. Also,
I believe if you hold down a key, you will get many onKeyPress events
for each
char that is processed but only one keyDown. I think you are right
though
that keyPress does not get called for all keys - I saw that it did not
get called on IE for a backspace (which makes sense since I assume
there is no
unicode defined for keys like a backspace.)

Thanks anyhow,
Fred Brown

Peter Hurford <pe***********@ microcrest.com> wrote in message

news:<3f******* *************** *@news.frii.net >...
I can't remember the exact details but I seem to recall having problems
trapping keys - esp. the tab key - with onkeypress.

My solution was to look at onkeydown instead.

I can think of lots of reasons why you'd want to do this, by the way.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 20 '05 #6

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

Similar topics

7
3228
by: julian.tklim | last post by:
Hi, I need to build an editable Datagrid with add & delete buttons on each row using javascript. DataGrid need not be pre-populated with values. To make the thing complicated, one of the column need to be a date picker field. I know things will be easier with ASPX datagrid.
0
9628
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
9464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10292
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...
0
10122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8954
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7471
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
5368
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...
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.