Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts

    tabindex auto jump

    this code works only with tabindex = 1,2,3

    --------------------------------------------------

    <script type="text/javascript">
    function toUnicode(elmnt,content)
    {
    if (content.length==elmnt.maxLength)
    {
    next=elmnt.tabIndex
    if (next<document.forms[0].elements.length)
    {
    document.forms[0].elements[next].focus()
    }
    }
    }
    </script>


    <input size="2" tabindex="1" id="one"
    maxlength="2" onkeyup="toUnicode(this,this.value)" />

    <input size="2" tabindex="2" id="two"
    maxlength="2" onkeyup="toUnicode(this,this.value)" />

    <input size="2" tabindex="3" id="three"
    maxlength="2" onkeyup="toUnicode(this,this.value)" />

    -----------------------------------
    if I use tabindex = 100,101,102 it doesn't work

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    It is because you are accessing the next field by its position in the form. If you use 1, 2, 3 the position is correct but if you use 101, 102, obviously it does not correspond to the position of the field in the form.

    try:

    Code:
    function toUnicode(elmnt)
    {
      var next;
      if (elmnt.value.length==elmnt.maxLength)
      {
        next=elmnt.tabIndex + 1;
        //look for the fields with the next tabIndex
        var f = elmnt.form;
        for (var i = 0; i < f.elements.length; i++)
        {
          if (next<=f.elements[i].tabIndex)
          {
            f.elements[i].focus();
            break;
          }
        }
      }
    }
    ...
    <input size="2" tabindex="1" id="one" maxlength="2" onkeyup="toUnicode(this)" />

  • #3
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts

    NOW ...

    .... it works !

    thankX


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •