Ruby Forum Ruby on Rails > problem in check_box

Posted by Leonard Yera (leonard2)
on 19.08.2008 21:11
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%><br />
<% end %>

but nothing happen when I click, no call to find2

any idea

thanks
Posted by Frederick Cheung (Guest)
on 19.08.2008 21:15
(Received via mailing list)
On 19 Aug 2008, at 20:11, Leonard Yera 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
Posted by Bill Walton (Guest)
on 19.08.2008 22:21
(Received via mailing list)
Hi Leonard,

Leonard Yera 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%><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
Posted by Shandy Nantz (snantz)
on 19.08.2008 22:30
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},
>         :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=#
   {mercado.id}'") %>
<%= check_box "mercado", "nombre", {:value=>mercado.id, 
:name=>mercado.nombre},
   :onclick => func1 %>


-S
Posted by Bill Walton (Guest)
on 20.08.2008 20:02
(Received via mailing list)
Shandy, Fred;

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

Best regards,
Bill