General discussion


Problem in IE5 Focus Method?

By ag2all ·
I posed this question before. Depending on the feedback, rephrasing the question. Please help with a solution, please.

Qs. Refer to attached code. It runs ok on IE4 and Netscape communicator version. But not in IE5. For example, if you enter "123" in area code field, IE4 enters "123" and then transfers focus to next field. But IE5 enters "12" and sets focus to next field, entering "3" in the next field.

How to solve this?
IS there any patch to correct this?
(This logic of field validation is used in entire range of applications. Checking IE version and then altering logic is one of the less preferable solutions.)

Ps. Users now are using both IE4 and IE5.

<script language="JavaScript">
function focont()
if(document.trial.area.value.length < 2)
if(document.trial.area.value.length == 2)
window.alert("reached 2")
return true
<tr bgcolor="66ccff">
<th>Contact Number</th>
<input name="area" type="text" size="3" maxlength="3" onKeyPress="focont()">
<input name="prefix" type="text" size="3" maxlength="3" >
<input name="number" type="text" size="4" maxlength="4">

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

Problem in IE5 Focus Method?

by Peter Ritchie In reply to Problem in IE5 Focus Meth ...

You have to keep in mind the the onKeyPress event occurs BEFORE the character is entered into the edit box (which has occured just before the onKeyUp event).

So, you'll want to to actually intercept the key up event instead of the key press event.
<input id="one" type="text" onkeyup="if (one.value.length > 2) {two.focus();}" size="3"><br/>
<input id="two" type="text">

This is all based on CSS 1 and should work in IE4, IE5 and Netscape 6.

One caveat to what is written above;you'll find that you tabbing doesn't work as nicely as you might expect. But, that's a side-effect of modifying default behaviour. You can easily intercept the onkeydown event and decide if you want to disable your onkeyup behavour depending on the character received.

Related Discussions

Related Forums