472,779 Members | 2,498 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Safari (Mac) - keysuppress(event) issue


The following code suppresses the 'enter' key, when run in I.E. 5.5 or
later (Windows) but not when run in Safari (Mac)

<body onkeypress="javascript:keysuppress(event)" >

function keysuppress(e)
{
if (e.type=="keypress" && e.keyCode=="13")
{
event.returnValue=false
}
}

What code can I use to suppress the 'enter' key when running an app in
Safari?

Thanks.

Jul 23 '05 #1
2 1978


Marcia Gulesian wrote:
The following code suppresses the 'enter' key, when run in I.E. 5.5 or
later (Windows) but not when run in Safari (Mac)

<body onkeypress="javascript:keysuppress(event)" >

function keysuppress(e)
{
if (e.type=="keypress" && e.keyCode=="13")
{
event.returnValue=false
}
}

What code can I use to suppress the 'enter' key when running an app in
Safari?
I don't have Safari here to test but the following hopefully works as it
uses both the W3C DOM Level 2 event handling preventDefault method and
the established return false to cancel the keypress event:

<html lang="en">
<head>
<title>keypress event handling</title>
<script type="text/javascript">
function init () {
document.onkeypress = function (evt) {
if (!evt && window.event) {
evt = window.event;
}
if (evt) {
var keyCode = evt.keyCode ? evt.keyCode :
evt.charCode ? evt.charCode : evt.which;
if (keyCode == 13) {
if (evt.preventDefault) {
evt.preventDefault();
}
return false;
}
else {
return true;
}
}
return true;
};
if (document.layers) {
document.captureEvents(Event.KEYPRESS);
}
}

init();
</script>
</head>
<body>
<form action="">
<p>
You should not be able to enter line breaks if the keypress event handling
works:
<br>
<textarea name="textareaName" rows="5" cols="80"Kibology for all.

</textarea>
</p>
</form>
</body>
</html>

Tested to work in IE 6, Netscape 7.1, Mozilla 1.7, Netscape 4.
Please report back to the group whether that solves the problem for Safari.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2
Martin Honnen wrote:

What code can I use to suppress the 'enter' key when running an app in
Safari?

<snip>
Tested to work in IE 6, Netscape 7.1, Mozilla 1.7, Netscape 4.
Please report back to the group whether that solves the problem for Safari.


Doesn't work in Safari 1.0.2, no errors.
Mick
Jul 23 '05 #3

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

Similar topics

5
by: sanj | last post by:
Hi all, My site is located at: http://www.eastdayspa.com/index.html I have use these main styles /* main styles */
3
by: Marcia Gulesian | last post by:
How can I make the following code run only when the cursor is in one text box and not in another? <body onkeypress="javascript:keysuppress(event)" function keysuppress(e) { if...
3
by: Marcia Gulesian | last post by:
document.getElementById("TextBox1").setAttribute("value","mm/dd/yyyy") works in Internet Explorer (Windows) but not in Safari (Mac). How can I insert a string into a textbox in the Safari browser?
7
by: aljamala | last post by:
Hi, I have a page that has a button "Exit and Close", which closes the popup window that it has opened. This works fine under IE, NN, FF and Opera but not Safari. Any ideas why? I even tried...
5
by: dvpnet | last post by:
Hi Hello, I recently created a website in IE6 using frames. My friend has a Mac, the browser is Firefox. The top frame cannot be entirely seen. Is it a Firefox or Mac issue? How can I be...
1
by: laltvm | last post by:
I have a strange issue with safari. My intention was to capture for the keystroke and increment and decrement a particular test box value by 1 or -1.The following is my code. var y=x.value...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.