...

View Full Version : move to next input?



angst
10-19-2005, 05:29 PM
hi,
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!

-Ken

pccode
10-19-2005, 06: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.



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

function setnum(elem) {
num = elem;
}
</script>

<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)">
</form>

angst
10-19-2005, 06: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!
-Ken

angst
10-19-2005, 07: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!
-Ken

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


<html>
<head>
<script type="text/javascript">
function Jump(CurElm, NextElm)
{
if(CurElm.value.length == 3) document.formname[NextElm].select();
}
</script>
</head>
<body>
<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="">
</form>
</body>
</html>


Good luck

angst
10-19-2005, 10:08 PM
kool!
exactly what i as looking for.

Thanks!

-Ken



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum