MAC Address

Input aceitar numeros e saltar proximo input

by dandrade78

HTML

<!--  Discusao em https://www.idaima.org/topic/882334/auto-tab-to-next-input-field-when-fill-4-characters/3
Baseado no codigo em http://jsfiddle.net/2VETF/1/ -->
<!-- codigo alternativo http://jsfiddle.net/dandrade78/L9s3p76k/1/ -->
<!-- Objetivos: Aceitar somente algarismos e pular os campos automaticamente apos prenchidos  
Problema autotab nao funciona, apesar de colar o HTML nos codigos originais e funcionar 

-->

<label> Address MAC </label>
<input class="inputs" type="text" maxlength="2" size="1" onkeypress="if (!isNaN(String.fromCharCode(window.event.keyCode))) return true; else return false;">
<input class="inputs" type="text" maxlength="2" size="1" onkeypress="if (!isNaN(String.fromCharCode(window.event.keyCode))) return true; else return false;">
<input class="inputs" type="text" maxlength="2" size="1" onkeypress="if (!isNaN(String.fromCharCode(window.event.keyCode))) return true; else return false;">
<input class="inputs" type="text" maxlength="2" size="1" onkeypress="if (!isNaN(String.fromCharCode(window.event.keyCode))) return true; else return false;">
<input class="inputs" type="text" maxlength="2" size="1" onkeypress="if (!isNaN(String.fromCharCode(window.event.keyCode))) return true; else return false;">
<input class="inputs" type="text" maxlength="2" size="1" onkeypress="if (!isNaN(String.fromCharCode(window.event.keyCode))) return true; else return false;">
<br><label>Número serial</label>
<input class="inputs" type="text" maxlength="10" width="10ch" onkeypress="if (!isNaN(String.fromCharCode(window.event.keyCode))) return true; else return false;">

CSS

input { margin: 5px;  }

JavaScript 1.7

$(function() {
    $(".inputs").keyup(function () {
        if (this.value.length == this.maxLength) {
          $(this).next('.inputs').focus();
        }
    });
});