473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.preventDefault(); // dom 2 (also tried without this here)
return false; // netscape
}
....
<body>
....
<TEXTAREA Name=demoTextarea ROWS=10 COLS=50 OnKeyPress="f(event)">
</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 9742
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***********@fractious.net wrote in message news:<yo*************@panix2.panix.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********@deltek.com
"Fred Brown" <fr***@inter.net.il> wrote in message
news:45**************************@posting.google.c om...
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
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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...

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.