Limit Text Box Length

[Total: 0    Average: 0/5]

This example limits the length of the input string in the text box.

Head Code:

<script>
function newChar()
{
var _RC=document.exf1.rc.value
if(_RC.length>document.exf1.rc.maxlength)
{
  alert("length exceeded");
  setTimeout("resetIt()",30);
}
else
{
  setTimeout("setThem();",30);
}
}
function setThem()
{
  var _RC=document.exf1.rc.value
  document.exf1.t1.value=_RC;
  document.exf1.h1.value=_RC;
}
function resetIt()
{
  document.exf1.rc.value=document.exf1.h1.value;
}
</script>

Body Code:

<form name=exf1>
<input type=text name=t1>
<input type=hidden name=h1>
<TEXTAREA NAME=rc  style="HEIGHT: 80pt; WIDTH: 490pt" maxlength="5" onkeypress=newChar()></textarea>
</form>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *