views:

91

answers:

1

Hello, I want to use observe_field to give me the character count of the textarea, updated as you type. What am I doing wrong here?

<div class="field">
  <%= observe_field :micropost_content,
      :function => "$('micropost_content').value.length" %>
  <%= f.text_area :content %>
</div>
A: 

If you don't set the frequency option it becomes event based (onchange.) Try:

<%= observe_field :micropost_content, :frequency => 1,
      :function => "$('micropost_content').value.length" %>
jdeseno
Event based is what I want.. I want it to change immediately when you type a key. I tried setting the frequency to one second like you suggested, though, and it still isn't showing anything above the text box.
nnyby
I think you need to change your function if you're using what's in your example, "$('micropost_content').value.length"; will just evaluate to some number, not do anything special. Try doing "alert('changed')" or something to see if it's working.
jdeseno