# Use The observe\_field Helper, or Something Else?

**URL:** <https://www.ruby-forum.com/t/use-the-observe-field-helper-or-something-else/137655>\
**Category:** Rails\
**Created:** [May 15, 2008, 1:34am UTC](https://www.ruby-forum.com/t/use-the-observe-field-helper-or-something-else/137655 "2008-05-15T01:34:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rornoob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7bcc69/32.png) [@rornoob](https://www.ruby-forum.com/u/rornoob)\
**Post date:** [May 15, 2008, 1:34am UTC](https://www.ruby-forum.com/t/use-the-observe-field-helper-or-something-else/137655/1 "2008-05-15T01:34:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rornoob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7bcc69/32.png) [@rornoob](https://www.ruby-forum.com/u/rornoob)\
**Post date:** [May 15, 2008, 3:00am UTC](https://www.ruby-forum.com/t/use-the-observe-field-helper-or-something-else/137655/2 "2008-05-15T03:00:22Z")

</div>

Here is a cleaner representation of the code:

[http://www.pastie.org/197264](http://www.pastie.org/197264)

thanks

---

<div class="post-metadata">

**Author:** ![rornoob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7bcc69/32.png) [@rornoob](https://www.ruby-forum.com/u/rornoob)\
**Post date:** [May 15, 2008, 3:05am UTC](https://www.ruby-forum.com/t/use-the-observe-field-helper-or-something-else/137655/3 "2008-05-15T03:05:38Z")

</div>

parent.target.document.form1.messagesubject.value

is extremely ugly.

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

---

<div class="post-metadata">

**Author:** ![rornoob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7bcc69/32.png) [@rornoob](https://www.ruby-forum.com/u/rornoob)\
**Post date:** [May 15, 2008, 6:20pm UTC](https://www.ruby-forum.com/t/use-the-observe-field-helper-or-something-else/137655/4 "2008-05-15T18:20:31Z")

</div>

I tried your suggestion:

[http://www.pastie.org/197620](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)” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![rornoob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7bcc69/32.png) [@rornoob](https://www.ruby-forum.com/u/rornoob)\
**Post date:** [May 15, 2008, 11:51pm UTC](https://www.ruby-forum.com/t/use-the-observe-field-helper-or-something-else/137655/5 "2008-05-15T23:51:44Z")

</div>

Did you include the default javascript files by using

\<%= javascript\_include\_tag :defaults %\> in your layout?

---

<div class="post-metadata">

**Author:** ![rornoob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7bcc69/32.png) [@rornoob](https://www.ruby-forum.com/u/rornoob)\
**Post date:** [May 16, 2008, 7:09pm UTC](https://www.ruby-forum.com/t/use-the-observe-field-helper-or-something-else/137655/6 "2008-05-16T19:09:01Z")

</div>

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

[http://www.pastie.org/198289](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)” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
