Capítulo 17

Formulários - Tabulação automática

JavaScript

<script type="text/javascript">
var formulario = document.getElementById("fdemo");	
formulario.ag.onkeyup = tabAuto;
formulario.cc.onkeyup = tabAuto;
formulario.dg.onkeyup = tabAuto;
function tabAuto(event) { 
	var event = event || window.event;
	var target = event.target || event.srcElement;
	if (target.value.length == target.maxLength) { 
	qdeControles = formulario.elements.length;
		for (var i=0; i<qdeControles; i++) {
			if (formulario.elements[i] == target) {
				formulario.elements[i+1].focus();
			}
		}	
	}
}
}
</script>

HTML

...
<form  action="http://www.maujor.com"  id="fdemo" method="get">
<label for="ag">Agência </label>
<input type="text" size="4" maxlength="4" name="ag" id="ag" /> 
<label for="cc">Conta:</label>
<input type="text" size="5" maxlength="5" name="cc" id="cc" /> - 
<input type="text" size="1" maxlength="1" name="dg" id="dg" /> 
<input type="submit" value="OK" id="ok" name="ok" />
</form>
...

-