MAC problems with onkeypress

S

Simon Wigzell

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top