David Williams <lists@ruby-forum.com> writes:
> I'm unable to get the character counter to show an initial value.
>
> When you type a something in, it says -1, -3, -4. It starts off at 0,
> instead of the maximum amount allowed. I'd prefer it countdown from the
> highest amount of characters allowed. 400, 399, 398, etc
>
> $(document).ready(function() {
> var counter, max_length, review_text;
> review_text = $('#body');
> counter = $('#counter');
> max_length = counter.data('maximum-length');
> review_text.keyup(function() {
> counter.text(max_length - ($(this).val().length));
> });
> });
>
> --
> Posted via http://www.ruby-forum.com/.
This is a Javascript question, and has nothing to do with Rails.
Nevertheless, I think you need to convert max_length to an integer. If
it is comming off whatever tag has id="counter" and
data-maximum-lenght="400", that is being pulled in as a String. Perhaps
try:
max_length = parseInt(counter.data('maximum-lenght'));
--
Tamara Temple
tamouse@gmail.com
http://www.tamouse.org
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/m2lh7u6r61.fsf%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment