View Full Version : move to next input?

10-19-2005, 04:29 PM
I've got a form where I need a use to enter an ip address, each octet has it's own text input, what I want to know, is if there is a way to make the courser jump to the next input box once the current one is filled in, just like configuring tcp/ip in windows networking. I've seen this done before, but i'm not sure how.

thanks in advance for your time!


10-19-2005, 05:34 PM
The only problem with the code below is that it assumes that the ip address being entered will contain 3 numbers in each octect. Otherwise it won't skip to the next input box.

num = 0;
onkeydown = function() {
if (document.formname.elements[num].value.length == 3) {
var attrib = eval('document.formname.elements[++num]');

function setnum(elem) {
num = elem;

<form name="formname">
<input type="text" name="inputname1" size=3 value="" onclick="setnum(0)">
<input type="text" name="inputname2" size=3 value="" onclick="setnum(1)">
<input type="text" name="inputname3" size=3 value="" onclick="setnum(2)">
<input type="text" name="inputname4" size=3 value="" onclick="setnum(3)">

10-19-2005, 05:44 PM
not sure if i'm missing something, but that doesn't work at all for me,
just allowed unlimited numbers to be entered into each box, and doesn't skip to the next one.

any ideas?

thanks again for your time!

10-19-2005, 06:20 PM
or if this can't be done, is there a way to just add in a dot automaticly every 3 digits?

thanks again for your time!

10-19-2005, 07:12 PM
You should check the length of the box with the onkeyup handler, and then do your move:

<script type="text/javascript">
function Jump(CurElm, NextElm)
if(CurElm.value.length == 3) document.formname[NextElm].select();
<form name="formname">
<input type="text" name="inputname1" size=3 value="" onkeyup="Jump(this, 'inputname2');">
<input type="text" name="inputname2" size=3 value="" onkeyup="Jump(this, 'inputname3');">
<input type="text" name="inputname3" size=3 value="" onkeyup="Jump(this, 'inputname4');">
<input type="text" name="inputname4" size=3 value="">

Good luck

10-19-2005, 09:08 PM
exactly what i as looking for.