Dear all,

I'm new to Rails and Web development, I have a problem about how to
"bind a JS event to a field within form_for block".

I have a JS function called checkLength, which is used to check the
length of words typed in a text area field:


HTML code with JS event invocation
========================================

<textarea id="micropost" name="micropost" rows="4" cols="60"
onpropertychange="checkLength(this,5);" oninput="checkLength(this,
5);">


Now I would like to reuse this JS funtion in another Rails view page,
which the src code is listed below:


_micropost_form.html.erb
=========================================

<%= form_for @micropost do |f| %>
....
f.text_area :content
....
<% end %>

The question is after I put the JS function under RAILS_APP/public/
javascript as custom.js and include it with javascript_include_tag.

HOW CAN I ADD AN EVENT AT THE TEXT_AREA FIELD WITHIN THE CODE :
f_text_area :content AND CALL THE JS FUNCTION LIKE :
oninput="checkLength(this, 5)"

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 6 | next ›
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedOct 21, '11 at 4:18p
activeOct 24, '11 at 1:56a
posts6
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase