Step 1: The following is the core code, which can be referenced on the page or encapsulated.
<Script language = "javascript" type = "text/javascript">
Function textLimitCheck (thisArea, maxLength, SpanId)
{
If (thisArea. value. length> maxLength)
{
ThisArea. value = thisArea. value. substring (0, maxLength );
ThisArea. focus ();
}
/* Write back the span value. Enter the text currently */
Var varss = '(remaining words:' + (maxLength-thisArea.value.length) + ')';
Document. getElementById (SpanId). innerHTML = varss;
}
</Script>
Step 2: apply this function to the text box
<Asp: TextBox ID = "txtOwner_Name" runat = "server" Width = "250px" MaxLength = "50" onkeyup = "textLimitCheck (this, 50, 'spowner _ name ') "BackColor =" Info "> </asp: TextBox>
<Span id = "spOwner_Name" style = "color: gray"> <em> (less than 50 words) </em> </span>
From Ai Zhi Chen