General discussion

Locked

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.

CODE:
<html>
<head>
<script language="JavaScript">
function focont()
{
window.alert(document.trial.area.value.length);
if(document.trial.area.value.length < 2)
{
document.trial.area.focus()
}
if(document.trial.area.value.length == 2)
{
window.alert("reached 2")
document.trial.prefix.focus()
}
return true
}
</script>
<body>
<FORM NAME="trial" ACTION="XX" METHOD=POST>
<table>
<tr bgcolor="66ccff">
<th>Contact Number</th>
</tr>
<tr>
<td>
<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">
</td>
</tr>
</table>
</FORM>
</body>
</html>

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| 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.
example:
<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.

Back to Windows Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums