The first step: The following is the core code, in the page reference or encapsulation can be.
Copy Code code as follows:
<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 value of span, currently fill in the text * *
var varss= ' (Remaining words: ' + (maxlength-thisarea.value.length) + ') ';
document.getElementById (Spanid). InnerHTML =varss;
}
</script>
Step Two: text box to apply this function
Copy Code code as follows:
<asp:textbox id= "Txtowner_name" runat= "width=" 250px "maxlength=" "onkeyup=" Textlimitcheck (this,50, ' Spowner_name ') "backcolor=" Info "></asp:TextBox>
<span id= "Spowner_name" style= "Color:gray" ><em> (within 50 words) </em></span>