Restricting MaxLength in Multiline Textbox Control using Javascript.

Posted by vishalneeraj-24503 under JavaScript category on | Points: 40 | Views : 663
If we specify maxlength property to multilne textbox,then it is not validated and allow to type continuously.And maxlength property only works in Singleline textbox.
So,to restrict multiline textbox,we use javascript function as below code:-

function Restrict_MaxLength(Object,MaxLen)
if(Object.value.length > MaxLen-1)
Object.value = Object.value.substring(0,MaxLen);
<asp:TextBox runat = "server" ID = "txt_comments" onkeypress = "javascript:return Restrict_MaxLength(this,400);"
onblur = "javascript:return Restrict_MaxLength(this,400)"
onchange = "javascript:return Restrict_MaxLength(this,400)" TextMode = "MultiLine" Rows="6"></asp:TextBox>

Comments or Responses

Login to post response