# Observe\_field and :function

**URL:** <https://www.ruby-forum.com/t/observe-field-and-function/114727>\
**Category:** Rails\
**Created:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/observe-field-and-function/114727 "2007-09-17T13:24:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 17, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/observe-field-and-function/114727/1 "2007-09-17T13:24:50Z")

</div>

Hi,

I m using the observe\_field helper with the :function attribute.

If I do the following everything it works without any issue:

\<%= observe\_field ‘select\_gender’, {:function =\> “(value == ‘2’) ?  
$(‘record\_ohrmarke’).value = ‘a boy’:  
$(‘record\_ohrmarke’).value = ‘a girl’;”} %\>

I would like to perform a more complicated processing and I thought it  
would be nice to do something like that:

…  
…

\<%= observe\_field ‘select\_gender’, {:function =\>  
“handle\_gender\_change(element,value);”} %\>

However, that results in an js error telling me that  
handle\_gender\_change is not defined…

Would be great if somebody could help me out here with the correct  
way.

thanks a lot in advance.

–  
volker

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 21, 2007, 1:55pm UTC](https://www.ruby-forum.com/t/observe-field-and-function/114727/2 "2007-09-21T13:55:41Z")

</div>

Hi,

well, just to give myself a response… 🙂

I was nt able to get it up and running with “infile” javascript. But  
if I place the function in a normal .js file everything is working  
fine.

–  
Volker

On 17 Sep., 12:33, “removed\_email\_address@domain.invalid”
