www.webdeveloper.com
Results 1 to 2 of 2

Thread: [RESOLVED] Javascript Limit Text Help

  1. #1
    Join Date
    Dec 2008
    Posts
    123

    resolved [RESOLVED] Javascript Limit Text Help

    Hi, I use the below js to limit the amount of text allow in a textarea field. My problem is once the limit is reached I cannot delete anything that was type. How do I limit the textarea to a max length and still allow deleting when it reaches the max length?

    Code:
    function limitText(Object, MaxLen)
    	{  return (Object.value.length <= MaxLen);}
    In the html
    HTML Code:
    onkeypress="return limitText(this, 250);"


    Thanks.

  2. #2
    Join Date
    Dec 2012
    Posts
    52
    <script language="javascript" type="text/javascript">
    function limitText(limitField, limitCount, limitNum) {
    if (limitField.value.length > limitNum) {
    limitField.value = limitField.value.substring(0, limitNum);
    } else {
    limitCount.value = limitNum - limitField.value.length;
    }
    }
    </script>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles