Max character for a text area field

i hardly ever write javascript and having a problem validating the max
characters in a text area field.

here is what i have:

<%= error_messages_for :comment %>

Comments

<% form_for(@comment, :html => {:onSubmit => ‘return validate(this);’})
do |f| %>

User Name
<%= f.text_field(:username, :size => 67) %>

Title
<%= f.text_field(:title, :size => 67) %>

Body
<%= f.text_area(:body, :size => "50x20") %>

<%= f.submit "Post Coment" %>

<% end %>

i’m having problems referencing my text area. can someone help?
thanks!

cant help with the referencing problem, but you should never do a
(solely)client-side validation of user data anyway.

It’s always best to do this at the server since even though you
validated it with javascript the user can send you a manipulated
request with whatever data he chose. So client-side validation would
only be a user-friendly feature, cause he gets instant feedback.

Rails offers lots of options for (server-side) data validation
(validates_presence_of, validates_length_of,
validates_numericality_of…)

hope that helps! good luck, simon

On Jun 24, 5:42 am, Scott K. [email protected]

smn wrote:

cant help with the referencing problem, but you should never do a
(solely)client-side validation of user data anyway.

It’s always best to do this at the server since even though you
validated it with javascript the user can send you a manipulated
request with whatever data he chose. So client-side validation would
only be a user-friendly feature, cause he gets instant feedback.

Rails offers lots of options for (server-side) data validation
(validates_presence_of, validates_length_of,
validates_numericality_of…)

hope that helps! good luck, simon

On Jun 24, 5:42�am, Scott K. [email protected]

I agree u should use validates_length_of rather than a JS for
restricting the user to a certain limit

Thanks

Dhaval P.
Software Engineer
Ruby on Rails
http://www.railshouse.com

thanks for the help! i used validates_length_of and it’s working
perfectly. Maybe one day i’ll go back to the javascript just to add
another user friendly reminder so they are aware before they submit the
form.

On Jun 24, 2008, at 8:20 PM, Scott K. wrote:

thanks for the help! i used validates_length_of and it’s working
perfectly. Maybe one day i’ll go back to the javascript just to add
another user friendly reminder so they are aware before they submit
the
form.

Coming in late, but this has worked for me… (wrapped to fit. i
hope). define the constants as necessary, change the instance
variables, etc.

chars left :
<%= UserBlog::MAX_CHARS -
(@blog.body.length rescue 0) -%>


<%= text_area_tag :body, (@blog.body rescue nil),
:onkeyup => “$(‘blog_counter’).update([#{UserBlog::MAX_CHARS} -
this.value.strip().length,
0].max())” %>