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!

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 %>

Here is a cleaner representation of the code:

http://www.pastie.org/197264

thanks

parent.target.document.form1.messagesubject.value

is extremely ugly.

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

I tried your suggestion:

http://www.pastie.org/197620

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.

Thanks!

On May 14, 6:04 pm, “Ryan B. (Radar)” [email protected]

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:

http://www.pastie.org/198289

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

… code

… code

…code

Thanks!

On May 15, 2:51 pm, “Ryan B. (Radar)” [email protected]