# Problem in check\_box

**URL:** <https://www.ruby-forum.com/t/problem-in-check-box/146293>\
**Category:** Rails\
**Created:** [August 19, 2008, 9:11pm UTC](https://www.ruby-forum.com/t/problem-in-check-box/146293 "2008-08-19T21:11:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![leonard2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e68b1a/32.png) [@leonard2](https://www.ruby-forum.com/u/leonard2)\
**Post date:** [August 19, 2008, 9:11pm UTC](https://www.ruby-forum.com/t/problem-in-check-box/146293/1 "2008-08-19T21: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},  
:onchange =\> remote\_function(:url =\> {:action =\> “find2”}, :with  
=\> “‘id=#{mercado.id}’”) %\> \<%=mercado.nombre%\>  
  
\<% end %\>

but nothing happen when I click, no call to find2

any idea

thanks

---

<div class="post-metadata">

**Author:** ![leonard2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e68b1a/32.png) [@leonard2](https://www.ruby-forum.com/u/leonard2)\
**Post date:** [August 19, 2008, 9:15pm UTC](https://www.ruby-forum.com/t/problem-in-check-box/146293/2 "2008-08-19T21:15:43Z")

</div>

On 19 Aug 2008, at 20:11, Leonard Y. wrote:

> \<% 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:** ![leonard2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e68b1a/32.png) [@leonard2](https://www.ruby-forum.com/u/leonard2)\
**Post date:** [August 19, 2008, 10:21pm UTC](https://www.ruby-forum.com/t/problem-in-check-box/146293/3 "2008-08-19T22:21:34Z")

</div>

Hi Leonard,

Leonard Y. wrote:

> \<% for mercado in @merca %\>  
> \<%= check\_box “mercado”, “nombre”, {:value=\>mercado.id,  
> :name=\>mercado.nombre},  
> :onchange =\> remote\_function(:url =\> {:action =\> “find2”}, :with  
> =\> “‘id=#{mercado.id}’”) %\> \<%=mercado.nombre%\>  
>   
> \<% 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:** ![leonard2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e68b1a/32.png) [@leonard2](https://www.ruby-forum.com/u/leonard2)\
**Post date:** [August 20, 2008, 8:02pm UTC](https://www.ruby-forum.com/t/problem-in-check-box/146293/4 "2008-08-20T20:02:46Z")

</div>

Shandy, Fred;

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

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![leonard2](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e68b1a/32.png) [@leonard2](https://www.ruby-forum.com/u/leonard2)\
**Post date:** [August 19, 2008, 10:30pm UTC](https://www.ruby-forum.com/t/problem-in-check-box/146293/5 "2008-08-19T22:30:27Z")

</div>

Leonard Y. 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},  
> :onchange =\> remote\_function(:url =\> {:action =\> “find2”}, :with  
> =\> “‘id=#{mercado.id}’”) %\> \<%=mercado.nombre%\>  
>   
> \<% 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=#  
{mercado.id}’”) %\>  
\<%= check\_box “mercado”, “nombre”, {:value=\>mercado.id,  
:name=\>mercado.nombre},  
:onclick =\> func1 %\>

-S
