# Observe\_field w/check\_box (how do you capture unchecked even

**URL:** <https://www.ruby-forum.com/t/observe-field-w-check-box-how-do-you-capture-unchecked-even/72578>\
**Category:** Rails\
**Created:** [October 18, 2006, 5:57am UTC](https://www.ruby-forum.com/t/observe-field-w-check-box-how-do-you-capture-unchecked-even/72578 "2006-10-18T05:57:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tate\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8edcca/32.png) [@Tate\_H](https://www.ruby-forum.com/u/Tate_H)\
**Post date:** [October 18, 2006, 5:57am UTC](https://www.ruby-forum.com/t/observe-field-w-check-box-how-do-you-capture-unchecked-even/72578/1 "2006-10-18T05:57:26Z")

</div>

Hi: Does observe\_field work w/check\_box?

When a checkbox is checked, all works. When it is unchecked, I get  
“undefined” for params[:option].

## more info on what I’m using:

my check\_box method produces this:

my observe\_field is:

\<%= observe\_field “option\_#{option}”,  
:update =\> ‘commandLine’,  
:url =\> {:action =\> ‘updateCommand’},  
:with =\> ‘option’,  
:on =\> ‘click’ %\>

---

<div class="post-metadata">

**Author:** ![Tate\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8edcca/32.png) [@Tate\_H](https://www.ruby-forum.com/u/Tate_H)\
**Post date:** [October 18, 2006, 7:05am UTC](https://www.ruby-forum.com/t/observe-field-w-check-box-how-do-you-capture-unchecked-even/72578/2 "2006-10-18T07:05:32Z")

</div>

For one of my applications the observer passes “1” when it is checked  
and  
“undefined” when it isn’t. “undefined” should probably be “0”, but you  
can  
still tell whether or not it is checked.

-Jonathan.

---

<div class="post-metadata">

**Author:** ![Tate\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8edcca/32.png) [@Tate\_H](https://www.ruby-forum.com/u/Tate_H)\
**Post date:** [October 18, 2006, 7:11am UTC](https://www.ruby-forum.com/t/observe-field-w-check-box-how-do-you-capture-unchecked-even/72578/3 "2006-10-18T07:11:32Z")

</div>

> For one of my applications the observer passes “1” when it is checked and  
> “undefined” when it isn’t. “undefined” should probably be “0”, but you can  
> still tell whether or not it is checked.

Maybe… but since there’s no “unchecked\_value” attribute it really is  
undefined… I think you’d be safer testing to see…

if params[:option] != “1” then…

where “1” is the value of the ‘value’ attribute. Cause some web browser  
might just decide to start returning false or nil or 0 instead of  
‘undefined’ so you’re test for ‘undefined’ would then fail…

Just a thought.

---

<div class="post-metadata">

**Author:** ![Tate\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8edcca/32.png) [@Tate\_H](https://www.ruby-forum.com/u/Tate_H)\
**Post date:** [October 18, 2006, 7:19am UTC](https://www.ruby-forum.com/t/observe-field-w-check-box-how-do-you-capture-unchecked-even/72578/4 "2006-10-18T07:19:32Z")

</div>

I forgot to mention I have lots of checkboxes for this view, so I can’t  
determine which box the uncheck was triggered from because of the  
‘undefined’.

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Jonathan V.  
Sent: Tuesday, October 17, 2006 11:03 PM  
To: removed\_email\_address@domain.invalid  
Subject: [Rails] Re: observe\_field w/check\_box (how do you capture  
unchecked  
event?)

For one of my applications the observer passes “1” when it is checked  
and  
“undefined” when it isn’t. “undefined” should probably be “0”, but you  
can  
still tell whether or not it is checked.

-Jonathan.

On 10/18/06, Tate H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

Hi: Does observe\_field work w/check\_box?

When a checkbox is checked, all works. When it is unchecked, I get  
“undefined” for params[:option].

[…]
