# problem in check\_box

**URL:** <https://discuss.rubyonrails.org/t/problem-in-check-box/33393>\
**Category:** rubyonrails-talk\
**Created:** [August 19, 2008, 7:11pm UTC](https://discuss.rubyonrails.org/t/problem-in-check-box/33393 "2008-08-19T19:11:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [August 19, 2008, 7:11pm UTC](https://discuss.rubyonrails.org/t/problem-in-check-box/33393/1 "2008-08-19T19:11:35Z")

</div>

hello list I have this check\_box in my code

\<% for mercado in @merca %\> \<%= check\_box "mercado", "nombre", {:value=\>mercado.id, :name=\>mercado.nombre}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:onchange =\> remote\_function(:url =\> {:action =\> "find2"}, :with =\> "'id=#{mercado.id}'") %\> \<%=mercado.nombre%\>\<br /\> \<% end %\>

but nothing happen when I click, no call to find2

any idea

thanks

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [August 19, 2008, 7:14pm UTC](https://discuss.rubyonrails.org/t/problem-in-check-box/33393/2 "2008-08-19T19:14:51Z")

</div>

> hello list I have this check\_box in my code
> 
> \<% for mercado in @merca %\> \<%= check\_box "mercado", "nombre", {:value=\>mercado.id, :name=\>mercado.nombre}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:onchange =\> remote\_function(:url =\> {:action =\>  
> "find2"}, :with =\> "'id=#{mercado.id}'") %\> \<%=mercado.nombre%\>\<br /\> \<% end %\>
> 
> but nothing happen when I click, no call to find2

the onchange should be part of the same options has as :value and :name

Fred

---

<div class="post-metadata">

**Author:** ![Bill\_Walton](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@Bill\_Walton](https://discuss.rubyonrails.org/u/Bill_Walton)\
**Post date:** [August 19, 2008, 8:20pm UTC](https://discuss.rubyonrails.org/t/problem-in-check-box/33393/3 "2008-08-19T20:20:47Z")

</div>

Hi Leonard,

Leonard Yera wrote:

> \<% for mercado in @merca %\> \<%= check\_box "mercado", "nombre", {:value=\>mercado.id, :name=\>mercado.nombre}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:onchange =\> remote\_function(:url =\> {:action =\> "find2"}, :with =\> "'id=#{mercado.id}'") %\> \<%=mercado.nombre%\>\<br /\> \<% end %\>
> 
> but nothing happen when I click, no call to find2

The check\_box helper doesn't take an :onchange option. You want to use observe\_field to watch the check\_box status.

HTH, Bill

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [August 19, 2008, 8:30pm UTC](https://discuss.rubyonrails.org/t/problem-in-check-box/33393/4 "2008-08-19T20:30:27Z")

</div>

Leonard Yera wrote:

> hello list I have this check\_box in my code
> 
> \<% for mercado in @merca %\> \<%= check\_box "mercado", "nombre", {:value=\>mercado.id, :name=\>mercado.nombre}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:onchange =\> remote\_function(:url =\> {:action =\> "find2"}, :with =\> "'id=#{mercado.id}'") %\> \<%=mercado.nombre%\>\<br /\> \<% end %\>
> 
> but nothing happen when I click, no call to find2
> 
> any idea
> 
> thanks

You want to use :onclick. I have the same code (well, almost) in one of my apps. The only difference is that my remote\_function call's value is placed within a variable:

\<% func1 = remote\_function(:url =\> {:action =\> "find2"}, :with =\> "'id=# &nbsp;&nbsp;&nbsp;{mercado.id}'") %\> \<%= check\_box "mercado", "nombre", {:value=\>mercado.id, :name=\>mercado.nombre}, &nbsp;&nbsp;&nbsp;:onclick =\> func1 %\>

-S

---

<div class="post-metadata">

**Author:** ![Bill\_Walton](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@Bill\_Walton](https://discuss.rubyonrails.org/u/Bill_Walton)\
**Post date:** [August 20, 2008, 6:02pm UTC](https://discuss.rubyonrails.org/t/problem-in-check-box/33393/5 "2008-08-20T18:02:11Z")

</div>

Shandy, Fred;

Thanks! I never knew we could use remote\_function this way. Learning something new every day!

Best regards, Bill
