Truncate values from multiline textbox after fix length in javascript

 
Truncate values from multiline textbox after fix length in javascript or How to truncate a string to a certain number of characters,

Example

Suppose you need to update a textbox with a description. Any description over 10 characters is truncated to 10.

<html>
<head> <script language="JavaScript">
 
    function maxtitle(txt,maxlength)
      { 
        if(txt.value.length > (maxlength-1))
          { 
            txt.value = txt.value.slice(0,maxlength);
            return false;
          }
      } 
    </script></head>
  <body>
 
    <form name=form1>
    Enter Name:
    <input type="text" name="txtNumber1" onkeyup="return maxtitle(this,10);">
 
    </form>
  </body>
</html>

Author: Pavan

I am asp.net developer have good knowledge of Asp.net ver 05,08,10 and good hand in sql server.Proficient in Object Oriented Programming and javascript, jQuery. Achievements - Integrate Spotfire, appnexus API ASP.net with sql server. Hobbies - Blogging ,Games, Movies ,Teaching,Keeping myself update with new technologies