Monday, September 15, 2008

Javascript to limit characters (length) in Text Area or Multiline TextBox

Bind the below function to keypress event as below

txtJustification.Attributes.Add("onkeypress", "return limitText('" + txtJustification.ClientID + "', 3000);");

function limitText(limitField, limitNum)
{
var obj = document.getElementById(limitField);
if (obj.value.length > limitNum){return false;} else return true;
}

Hope this helps

No comments: