I'm trying to drop the contents of @show_openers.subject and
@show_upeners.body into the onlick event of my dropdown whenever it is
changed. Is the solution to use the observe_field helper? If yes, what
is the best approach? I'm new to programming and RoR and am having a
REALLY hard time chaining it together in my head - any help is
appreciated!
CONTROLLER:
def bar
@show_openers = Opener.find(:all, :order => "description")
end
VIEW:
<% form_for :bar, :url => { :action => :bar } do |form| %>
<# when this is changed... %>
<%= collection_select("openers", "opener_id",
@show_openers, :id, :description ) %>
<# ...update the HERE_IS_SUBJECT and HERE_IS_BODY values %>
<%= submit_tag "insert opener",
:onClick =>
"parent.target.document.form1.messagesubject.value='HERE_IS_SUBJECT',
parent.target.document.form1.messagebody.value='HERE_IS_BODY'" %>
<% end %>
But it doesn't work - my FireBug console says, "$("messagesubject")
has no properties". Please keep in mind that I'm using frames (if that
matters). I'm new to programming and especially JavaScript, so I'm a
little slow right now.
That being said, the main piece I'm trying to solve right now is how
to get my messagebody and messagesubject tags to swap out on an
onChange event from my drop down - basically, take the values for the
currently select option and jam them into HERE_IS_SUBJECT and HERE_IS
BODY.