Tab automático em formulário com Javascript
Abaixo estarei exemplificando com um script Javascript o tab automático ao preencher um formulário pelo usuário Para que o script funcione você deve inserir o código abaixo em cada formulário onKeyup="autotab(this, document.telephone.phone1)"...
A
Admin
06 Oct, 2008 ·
1 min de leitura
Abaixo estarei exemplificando com um script Javascript o tab automático ao preencher um formulário pelo usuário
Para que o script funcione você deve inserir o código abaixo em cada formulário
onKeyup="autotab(this, document.telephone.phone1)" maxlength=1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script>
function autotab(current,to){
if (current.getAttribute &&
current.value.length==current.getAttribute("maxlength")) {
to.focus()
}
}
</script>
<b>Enter your phone number ex (1-888-555-1234):</b>
<form name="telephone">
<input type="text" name="phone0"
size=2 onKeyup="autotab(this, document.telephone.phone1)" maxlength=1>-
<input type="text" name="phone1"
size=4 onKeyup="autotab(this, document.telephone.phone2)" maxlength=3>-
<input type="text" name="phone2"
size=4 onKeyup="autotab(this, document.telephone.phone3)" maxlength=3>-
<input type="text" name="phone3" size=5 maxlength=4>
</form>
</body>
</html>