Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > JavaScript > Re: Limit <text...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 8 Topic 35542 of 37156
Post > Topic >>

Re: Limit <textarea> length without losing caret position

by Thomas 'PointedEars' Lahn <PointedEars@[EMAIL PROTECTED] > May 20, 2008 at 03:21 PM

pradeep wrote:
> <script>

  <script type="text/javascript">

> function textLimit(field, maxlen)
> {
>   if (field.value.length > maxlen)
>   {
>     field.value = field.value.substring(0, maxlen); // if the length
> is more than the limit (maxlen) then take only the first 'maxlen' no.
> of characters
>   }
>   return (maxlen - field.value.length);   // current value length is
> returned back
> }
> </script>
> 
> <textarea onkeyup='textLimit(this,100);return false'></textarea>

| but all my Google searches either lead to obsolete scripts that
| overwrite the "value" property (thus losing caret position)


PointedEars
-- 
    realism:    HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness:    XHTML 1.1 as application/xhtml+xml
                                                    -- Bjoern Hoehrmann
 




 8 Posts in Topic:
Limit