Thursday, 13 June 2013

Chnage focus to next field when the value reaches to maximum length. javascript example


<html>
<head>
<script language="javascript">
function jumpNext(x,y){
  if (y.length==x.maxLength){
    var next=x.tabIndex;
    if (next<document.getElementById("myForm").length){
      document.getElementById("myForm").elements[next].focus();
    }
  }
}
</script>
</head>
<body>
<center>
<b>Enter your date of birth in DD MM
and YYYY formate such as 24 11 2001</b>
<br>
<br>
<form id="myForm" >
  <input size="3" tabindex="1" maxlength="2"
    onkeyup="jumpNext(this,this.value)">
  <input size="2" tabindex="2" maxlength="2"
    onkeyup="jumpNext(this,this.value)">
  <input size="3" tabindex="3" maxlength="4"
    onkeyup="jumpNext(this,this.value)">
</form>
</center>
</body>
</html>




No comments:

Post a Comment