Use The observe_field Helper, or Something Else?

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!


def bar   @show_openers = Opener.find(:all, :order => "description") end


<% 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 => "'HERE_IS_SUBJECT','HERE_IS_BODY'" %> <% end %>

Here is a cleaner representation of the code:


is extremely ugly.

Why not just do $(‘messagesubject’).value?

I tried your suggestion:

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.


Did you include the default javascript files by using

<%= javascript_include_tag :defaults %> in your layout?

Yes - here are all 3 files that make up the framed page:

I've included them all under the same pastie, so I broke the pasted code up like so:

<!-- -------------------- --> <!-- index.html.erb --> <!-- -------------------- --> ... code

<!-- ---------------- --> <!-- bar.html.erb --> <!-- ---------------- --> ... code

<!-- --------------------- --> <!-- target.html.erb --> <!-- --------------------- --> ...code