Web Analytics Made Easy -
StatCounter Text boxes which flow into each other - CodingForum

Announcement

Collapse
No announcement yet.

Text boxes which flow into each other

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Text boxes which flow into each other

    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

  • #2
    I am not sure that I am correctly understanding your requirement, but try this:-

    Code:
    <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

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

    Comment


    • #3
      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
      Last edited by Thrillseeker; Aug 30, 2011, 03:10 PM.

      Comment


      • #4
        Code:
        <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.
        Be yourself. No one else is as qualified.

        Comment


        • #5
          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.

          Comment


          • #6
            Well, that wasn't what he asked. But that's easy, too:
            Code:
            <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.
            Be yourself. No one else is as qualified.

            Comment


            • #7
              Code:
              <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>
              Be yourself. No one else is as qualified.

              Comment


              • #8
                Originally posted by Old Pedant View Post
                __________________
                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!

                Comment


                • #9
                  Originally posted by jmrker View Post
                  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.
                  Be yourself. No one else is as qualified.

                  Comment

                  Working...
                  X
                  😀
                  🥰
                  🤢
                  😎
                  😡
                  👍
                  👎