Javascript language

adplus-dvertising
How to create a field's max length
Previous Home Next

How to create a field's max length using JavaScript

Step 1. Written below code in your application

<html>
<script language="javascript">
function chek_leng(x,y)
{
if (y.length==x.maxLength)
	{
	var next=x.tabIndex
	if (next<document.getElementById("myForm").length)
		{
		document.getElementById("myForm").elements[next].focus()
		}
	}
}
</script>
<body>
<p>Enter your key value:</p>
<form id="myForm">
<input size="4" tabindex="1" maxlength="4" onkeyup="chek_leng(this,this.value)">
<input size="2" tabindex="2" maxlength="2" onkeyup="chek_leng(this,this.value)">
<input size="3" tabindex="3" maxlength="3" onkeyup="chek_leng(this,this.value)">
</form>
</body>
</html>

Step 2. Run the Application.

Previous Home Next