...

View Full Version : Text boxes which flow into each other



Thrillseeker
08-30-2011, 02:53 PM
I've looked all over google but can't seem to find this out.

How do you make it so you have 2 text boxes beside each other where you type (for example) 1 character in the first, and it flows into the next (without the need for pressing tab or whatever)

I'm talking about the sort of thing you get when entering a software key

Philip M
08-30-2011, 06:52 PM
I am not sure that I am correctly understanding your requirement, but try this:-


<input type = "text" id = "textbox1" onkeyup = "copyit()">
<input type = "text" id = "textbox2" readonly>

<script type = "text/javascript">
function copyit() {
var x = document.getElementById("textbox1").value;
document.getElementById("textbox2").value= x;
}
</script>


I just said that in exactly the same but different words. - Footballer interviewed on BBC Radio 4

Thrillseeker
08-30-2011, 09:05 PM
No, not really. The above just copies it.


I'll give the example. Say someone types in "B20". I want the B to be in one textbox and the 20 to be in another alongside (as they do diff functions). So when someone types the B, i want it to shift to the next box before they type 20. Does that make sense?

Like someone said before, its just like you get in serial keys


I've just managed it by using the charAt.n command, but i'd still be interested to know how to do the flowing text boxes

Old Pedant
08-30-2011, 09:27 PM
<html>
<body>
<form>
<input name="first" size="1" onkeyup="this.form.second.focus();"/>
<input name="second" size="5"/>
</form>
</body>
</html>

Now...what do you do if the user hits the backspace key? Without first hitting any other key? After hitting some other key?

And do you want to insist that the first field contain only a letter?

Give a more complete specification of what you need and we can write more complete code.

devnull69
08-30-2011, 11:00 PM
He tried to do that already. I think you know those serial number text boxes that Microsoft used to show for their product keys.

There were like 4 text boxes, each for 4 digit key parts. So after you entered the fourth digit in the first text box the cursor automatically jumped into the second box and so forth.

Old Pedant
08-30-2011, 11:19 PM
Well, that wasn't what he asked. But that's easy, too:


<html>
<body>
<form>
Enter your phone number, area code first:
<input name="first" size="3" onkeyup="if ( this.value.length >= 3 ) this.form.second.focus();"/>
<input name="second" size="4"onkeyup="if ( this.value.length >= 3 ) this.form.third.focus();"/>
<input name="third" size="4" />
</form>
</body>
</html>

And of course you could easily also change it so it only accepts digits in each box.

Old Pedant
08-30-2011, 11:27 PM
<html>
<head>
<script type="text/javascript">
function digits(fld,next,max)
{
fld.value = fld.value.replace( /\D/g, "" );
if ( max != null && fld.value.length >= max )
{
next.focus();
}
}
</script>
</head>
<body>
<form>
Enter your phone number, area code first:
<input name="first" size="3" onkeyup="digits(this,this.form.second,3);"/>
<input name="second" size="4"onkeyup="digits(this,this.form.third,3); "/>
<input name="third" size="4" onkeyup="digits(this,this.form.fname,4);" />
<br/><br/>
Enter your first name: <input name="fname" />
</form>
</body>
</html>

jmrker
08-31-2011, 03:02 AM
__________________
Sadly, I am no longer young enough to know everything..
With thanks to Philip M.

I like your code and your new observation, but I would add the following:
...but I'm glad I'm old enough to remember my stupid mistakes!

Old Pedant
08-31-2011, 03:16 AM
I like your code and your new observation, but I would add the following:
...but I'm glad I'm old enough to remember my stupid mistakes!


Well, that may fit you, but for me...

...and I'm senile enough to not remember when I thought I did.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum