# Character Counter (javascript required?)

**URL:** <https://www.ruby-forum.com/t/character-counter-javascript-required/175341>\
**Category:** Rails\
**Created:** [September 11, 2009, 2:02pm UTC](https://www.ruby-forum.com/t/character-counter-javascript-required/175341 "2009-09-11T14:02:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [September 11, 2009, 2:02pm UTC](https://www.ruby-forum.com/t/character-counter-javascript-required/175341/1 "2009-09-11T14:02:08Z")

</div>

Can anyone help me out with a javascript walk through. I assume this is  
something that lots of other’s have done. I have an Advert form and on  
it I have a text\_field “Advert.description”, it’s validated on  
characters, 10…1000, nothing to see here, all perfectly normal, all  
working fine.

Now then, I’d like one of those twitter like character count downs above  
the field so the user can see how much they’re got left to type or if  
they’ve gone over the limit, BEFORE they submit. You get the picture.  
How to do? I’d really appreciate a worked example.

Cheers

bb

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [September 11, 2009, 3:19pm UTC](https://www.ruby-forum.com/t/character-counter-javascript-required/175341/2 "2009-09-11T15:19:49Z")

</div>

bingo bob wrote:

> Can anyone help me out with a javascript walk through. I assume this is  
> something that lots of other’s have done. I have an Advert form and on  
> it I have a text\_field “Advert.description”, it’s validated on  
> characters, 10…1000, nothing to see here, all perfectly normal, all  
> working fine.
> 
> Now then, I’d like one of those twitter like character count downs above  
> the field so the user can see how much they’re got left to type or if  
> they’ve gone over the limit, BEFORE they submit. You get the picture.  
> How to do?

This is not a Rails question. You’ll have better luck on a JavaScript  
list.

> I’d really appreciate a worked example.

Translation: “I’d really appreciate it if someone would do my work for  
me.” I’m sure others will help with problems, but you know, you have to  
actually make some effort here. Try writing it yourself, then ask a JS  
forum about what doesn’t work.

> Cheers

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

> bb

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [September 11, 2009, 3:33pm UTC](https://www.ruby-forum.com/t/character-counter-javascript-required/175341/3 "2009-09-11T15:33:38Z")

</div>

> bingo bob wrote:
> 
> > Can anyone help me out with a javascript walk through. I assume this is  
> > something that lots of other’s have done. I have an Advert form and on  
> > it I have a text\_field “Advert.description”, it’s validated on  
> > characters, 10…1000, nothing to see here, all perfectly normal, all  
> > working fine.
> > 
> > Now then, I’d like one of those twitter like character count downs above  
> > the field so the user can see how much they’re got left to type or if  
> > they’ve gone over the limit, BEFORE they submit. You get the picture.  
> > How to do?

How about using observe\_field, and triggering some kind of action every  
.2 second that counts how many characters there are, then updates some  
kind of div?

Note that I don’t know exactly how this works, so you may be going back  
to your server every .2 seconds to get an update. If you’re lucky, the  
action will be embedded in your page and it’ll be done on the  
client-side… But Marnen is right, this is, at the core, a Javascript  
question.

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [September 13, 2009, 12:21am UTC](https://www.ruby-forum.com/t/character-counter-javascript-required/175341/4 "2009-09-13T00:21:47Z")

</div>

On Sep 11, 8:02 am, bingo bob [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> How to do? I’d really appreciate a worked example.

[http://tinyurl.com/ppxf8e](http://tinyurl.com/ppxf8e)

–Matt J.
