JavaScript - AutoTab

<< Click to Display Table of Contents >>

Navigation:  Miscelânea >

JavaScript - AutoTab

Previous pageReturn to chapter overviewNext page

Default.aspx

 

<head runat="server">

  <title></title>

  <script type="text/javascript">

 

      function autotab(elemento) {

          if (elemento.value.length < elemento.getAttribute("maxlength")) return;

          var formulario = elemento.form;

          var els = formulario.elements;

          var x, autotab;

          for (var i = 0, len = els.length; i < len; i++) {

               x = els[i];

              if (elemento == x && (autotab = els[i + 1])) {

                  if (autotab.focus) autotab.focus();

               }

           }

       }

  </script>

</head>

<body>

  <form id="form1" runat="server">

  <asp:Label ID="lblFone" runat="server">Max 5 caracters:</asp:Label>

  <br />

  <asp:TextBox ID="txtFone" runat="server" onkeyup="autotab(this);" MaxLength="5"></asp:TextBox>

  <br />

  <br />

  <asp:Label ID="lblData" runat="server">Max 8 caracters:</asp:Label>

  <br />

  <asp:TextBox ID="txtData" runat="server" onKeyUp="autotab(this);" MaxLength="8"></asp:TextBox>

  <br />

  <br />

  <asp:Label ID="lblCEP" runat="server">Max 6 caracters:</asp:Label>

  <br />

  <asp:TextBox ID="txtCEP" runat="server" onKeyUp="autotab(this);" MaxLength="6"></asp:TextBox>

  <br />

  <br />

  <asp:Label ID="lblPlaca" runat="server">Max 2 caracters:</asp:Label>

  <br />

  <asp:TextBox ID="txtPlaca" runat="server" onKeyUp="autotab(this);" MaxLength="2"></asp:TextBox>

  </form>

</body>

 

Atenção

 

Não aceita shift-tab