Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q335 Is there a way to automatically put focus on the next input text field and continue to have to user typing when the previous input text field is full?

irt.org | Knowledge Base | JavaScript | Form 2 | Q335 [ previous next ]

Q335 Is there a way to automatically put focus on the next input text field and continue to have to user typing when the previous input text field is full?

Only in Netscape Navigator 4 or Internet Explorer 4:

<head>

<script language="JavaScript"><!--
function KeyPress(what,e,max,action) {
    if (document.layers) {
        if (e.target.value.length >= max)
            eval(action);
    }
    else if (document.all) {
        if (what.value.length > (max-1))
            eval(action);
    }
}
//--></script>

</head>

<body>

<form>

  <input type="text" name="text1" size="1" maxlength="1" onKeyUp="KeyPress(this,event,1,'what.form.text2.focus()')">
- <input type="text" name="text2" size="2" maxlength="2" onKeyUp="KeyPress(this,event,2,'what.form.text3.focus()')">
- <input type="text" name="text3" size="3" maxlength="3" onKeyUp="KeyPress(this,event,3,'what.form.text4.focus()')">
- <input type="text" name="text4" size="4" maxlength="4" onKeyUp="KeyPress(this,event,4,'what.form.text5.focus()')">
- <input type="text" name="text5" size="5" maxlength="5" onKeyUp="KeyPress(this,event,5,'what.form.text6.focus()')">
- <input type="text" name="text6" size="6" maxlength="6" onKeyUp="KeyPress(this,event,5,'what.form.text6.focus()')">
</form>

</body>

Johan Sundström writes:

Additional restraint on where it works: Netscape Navigator on Unix (at least 4.75 and below) don't succeed in doing this using just an onKeyUp handler.

Feedback on 'Q335 Is there a way to automatically put focus on the next input text field and continue to have to user typing when the previous input text field is full?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.