# Check\_box and rjs

**URL:** <https://www.ruby-forum.com/t/check-box-and-rjs/149825>\
**Category:** Rails\
**Created:** [September 30, 2008, 10:41am UTC](https://www.ruby-forum.com/t/check-box-and-rjs/149825 "2008-09-30T10:41:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [September 30, 2008, 10:41am UTC](https://www.ruby-forum.com/t/check-box-and-rjs/149825/1 "2008-09-30T10:41:02Z")

</div>

Hi,  
In my view I currently have the following link which show/hides a div  
\<%= link\_to\_function “Show Hide” do |page|  
page[:user\_input\_name].toggle  
end %\>

Instead of using a link to do the show/hiding I would like to use the  
onclick event of a checkbox. I understand that I can add javascript to  
the onclick event as follows:  
\<%= form.check\_box :io\_1 ,{:onclick =\> “alert(‘Testing’);”}%\>

However, is it possible to use rjs code in the onclick part of the  
form.check\_box?  
I know that i can look at the view and grab the javascript generated by  
the link and explicitly paste that into the onclick part but I like  
using the RJS syntax. Is it possible? e.g. something like:  
\<%= form.check\_box :io\_1 ,{:onclick =\> do |page|  
page[:user\_input\_name].toggle end }%\>

Thanks

---

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [September 30, 2008, 10:55am UTC](https://www.ruby-forum.com/t/check-box-and-rjs/149825/2 "2008-09-30T10:55:08Z")

</div>

On 30 Sep 2008, at 09:41, Tim C. wrote:

> the onclick event as follows:

That’s basically what update\_page does. The name is a bit misleading,  
but basically it yields the same thing as you get in a render :update  
or the magic page object in a rjs file and returns the generated  
javascript.

Fred

---

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [September 30, 2008, 11:16am UTC](https://www.ruby-forum.com/t/check-box-and-rjs/149825/3 "2008-09-30T11:16:24Z")

</div>

sorry, so how do I use updaet\_page in conjuction with a checkbox? The  
following doesn’t work:  
\<%= form.check\_box :io\_1 , update\_page{|page|  
page[:user\_input\_name].toggle}%\>

---

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [September 30, 2008, 11:21am UTC](https://www.ruby-forum.com/t/check-box-and-rjs/149825/4 "2008-09-30T11:21:12Z")

</div>

Apologies, I was being stupid. The correct way is:  
\<%= form.check\_box :io\_1 , :onclick =\> update\_page{|page|  
page[:user\_input\_name].toggle}%\>

Thanks for your help
