Saturday, March 30, 2013

Limiting Textarea Text,

In max length is not working when text mode is set to multi line.
To achieve same functionality for text area , we can call same function two event
onkeyup =" return CheckMaxLenghtOfMessage(this,160)" onchange =" return CheckMaxLenghtOfMessage(this,160)"

OnKeyup will come in light when user typing text by keybord.
OnChange will come in light when user copy paste the text in values.

solution is that only trim the extra value.

  function CheckMaxLenghtOfMessage(sender, maxlimit) {
if (sender.value.length >= maxlimit) {

sender.value = sender.value.substring(0, maxlimit);

     <asp:TextBox ID="test" runat="server" onkeyup =" return CheckMaxLenghtOfMessage(this,10)" onchange =" return CheckMaxLenghtOfMessage(this,160)" TextMode="MultiLine"></asp:TextBox>

Mahesh k Sharma

No comments: