473,406 Members | 2,208 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,406 software developers and data experts.

MAC problems with onkeypress

I'm using a javascript function to interecept all key presses and check for
valid character and also check the length of the current string and if it is
greater than a sent value, set the focus to the next field. I use this for
input for a phone number in the format NNN NNN NNNN it will only allow
numbers and will go to the 2nd field when there are 3 characters in the
first field and go to the 3rd field when there are 3 characters in the
second field and so on for any extension.

All works great on a PC with all kinds of browsers. Does not work on the MAC
with MAC IE or Safari.

The routine is called like this:

<input onkeypress="return NextField(this, event, 3,'Phone2')" name="Phone1">
<input onkeypress="return NextField(this, event, 3,'Phone3')" name="Phone2">
<input onkeypress="return NextField(this, event, 4,'Extension')"
name="Phone3">
Ext:
<input onkeypress="return NextField(this, event, 4,'')" name="Extension">

If the character is illegal (non-numeric) the subroutine returns false. On a
PC this is enough that the character will not be put into the field. Not so
on the MAC, even though the code executes and I get the error message, the
character will still appear in the field.

Also, when it is time to set the focus to the next field, this also fails on
the Mac. Setting focus on the MAc works fine with:

document.FormName.FieldName.focus();

but not with:

if (document.getElementById)
{
document.getElementById(NextField).focus();
}
else if (document.all)
{
document.all[NextField].focus();
}
else if (document.layers)
{
document.layers[NextField].focus();
}

(It executes the first option, document.getElementById(NextField).focus();)

where NextField is the passed in argument.

In fact the javascript breaks at this point.

Any workarounds for Mac?

Thanks
Mar 7 '06 #1
1 1866
Simon Wigzell wrote:
<input onkeypress="return NextField(this, event, 3,'Phone2')" name="Phone1">
<input onkeypress="return NextField(this, event, 3,'Phone3')" name="Phone2">
<input onkeypress="return NextField(this, event, 4,'Extension')"
name="Phone3">


Try this one: <URL:http://jsfromhell.com/forms/auto-tab>
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Mar 7 '06 #2

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

Similar topics

5
by: Albert Wagner | last post by:
I have included a file below that tests onKeyPress in Opera 7.11. I am getting peculiar behavior. When the file is first loaded, pressing the keypad + causes the textarea to get physically larger...
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...
3
by: euler | last post by:
why did the keydown event not fire in this simple example? <HTML> <HEAD><title>keydown_div</title> <script type="text/javascript"> function keydown() { alert("keydown"); } </script>
17
by: Julia Briggs | last post by:
Are there any gotchas using if (event.keyCode==8)? I understand that to represent backspace, but it doesn't work. I am running Windows XP, using a typical keyboard - but no luck in detecting...
11
by: LilAndy23 | last post by:
How can I use the onKeyPress event handler in Firefox? onKeyPress doesn't seem to fire in Firefox.
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...
5
by: ross kerr | last post by:
Hi All, I am extending the combobox to create a control that selects an item based on the text the user is typing into the text area of the control. I have an issue that occurs only when i...
1
by: vega80 | last post by:
Hi. I have a problem with assigning an onkeypress-function to dynamically created input-boxes.I want to put the content of an input-field into a tag-list when the user hits enter. This works...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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
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,...

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.