# Ajax Checkbox using Rails

**URL:** <https://www.ruby-forum.com/t/ajax-checkbox-using-rails/60422>\
**Category:** Rails\
**Created:** [May 13, 2006, 12:59pm UTC](https://www.ruby-forum.com/t/ajax-checkbox-using-rails/60422 "2006-05-13T12:59:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ronen\_Levi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@Ronen\_Levi](https://www.ruby-forum.com/u/Ronen_Levi)\
**Post date:** [May 13, 2006, 12:59pm UTC](https://www.ruby-forum.com/t/ajax-checkbox-using-rails/60422/1 "2006-05-13T12:59:25Z")

</div>

Hi,

I’m trying to have a checkbox, that when clickes sends an update to the  
server and in turn modify the UI with feedback on the success of the  
operation.

The main difficulty I’m encountering is that I can’t pass the checkbox  
value if I use the standard PrototypeHelpers.

I’m using remote\_function to build the function call, but it doesn’t  
allow me to pass the “this.checked” from the combo to the server. As far  
as I understand, the url should be written in the javascript as  
“/item/5/”+this.checked, but since the url is build only of options I  
can’t generate this.

1. How can this be done?
2. Why isn’t there checkbox\_remote just like there is link\_to\_remote. I  
would expect this also for all controls (radio buttons, edit boxes,  
etc.) so maybe it is hiding there somewhere?
3. Any workaround using other methods or assistance how write my own  
checkbox\_remote without duplicating too much existing rails code? (as I  
need to modify also the url\_for to get this solved). I’d prefer to to  
simply generate the whols javascript myself - I’d rather use ruby  
methods for everything.

Thanks,  
Ronen

---

<div class="post-metadata">

**Author:** ![Ronen\_Levi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@Ronen\_Levi](https://www.ruby-forum.com/u/Ronen_Levi)\
**Post date:** [May 13, 2006, 3:09pm UTC](https://www.ruby-forum.com/t/ajax-checkbox-using-rails/60422/2 "2006-05-13T15:09:26Z")

</div>

I think what you want to use is a field observer.

[http://api.rubyonrails.com/classes/ActionView/Helpers/PrototypeHelper.html#M000421](http://api.rubyonrails.com/classes/ActionView/Helpers/PrototypeHelper.html#M000421)

It’s really easy, and has the same syntax as link\_to\_remote.

---

<div class="post-metadata">

**Author:** ![Ronen\_Levi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@Ronen\_Levi](https://www.ruby-forum.com/u/Ronen_Levi)\
**Post date:** [May 13, 2006, 3:45pm UTC](https://www.ruby-forum.com/t/ajax-checkbox-using-rails/60422/3 "2006-05-13T15:45:00Z")

</div>

Bryan D. wrote:

> I think what you want to use is a field observer.
> 
> [Peak Obsession](http://api.rubyonrails.com/classes/ActionView/Helpers/PrototypeHelper.html#M000421)
> 
> It’s really easy, and has the same syntax as link\_to\_remote.

Not exactly since I want to have immediate response after the checkbox  
is pressed. Not one that is delayed.

Ronen

---

<div class="post-metadata">

**Author:** ![Ronen\_Levi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@Ronen\_Levi](https://www.ruby-forum.com/u/Ronen_Levi)\
**Post date:** [May 13, 2006, 5:41pm UTC](https://www.ruby-forum.com/t/ajax-checkbox-using-rails/60422/4 "2006-05-13T17:41:20Z")

</div>

Ronen Levi wrote:

> Bryan D. wrote:
> 
> > I think what you want to use is a field observer.
> > 
> > [Peak Obsession](http://api.rubyonrails.com/classes/ActionView/Helpers/PrototypeHelper.html#M000421)
> > 
> > It’s really easy, and has the same syntax as link\_to\_remote.
> 
> Not exactly since I want to have immediate response after the checkbox  
> is pressed. Not one that is delayed.
> 
> Ronen

correct me if im wrong here like, but wouldnt you just set the frequency  
to 0, hence making it event based and doing what you want when the  
checkbox is clicked?

like i said correct me if im wrong, but it seems pretty self-explanitory  
in the docs

---

<div class="post-metadata">

**Author:** ![Ronen\_Levi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@Ronen\_Levi](https://www.ruby-forum.com/u/Ronen_Levi)\
**Post date:** [May 13, 2006, 5:47pm UTC](https://www.ruby-forum.com/t/ajax-checkbox-using-rails/60422/5 "2006-05-13T17:47:24Z")

</div>

Ronen Levi wrote:

> Adam Holt wrote:
> 
> > correct me if im wrong here like, but wouldnt you just set the frequency  
> > to 0, hence making it event based and doing what you want when the  
> > checkbox is clicked?
> > 
> > like i said correct me if im wrong, but it seems pretty self-explanitory  
> > in the docs
> 
> Oops, didn’t notice the statement that 0 will take a different approach.  
> Thanks - I’ll try that.

no problem

---

<div class="post-metadata">

**Author:** ![Ronen\_Levi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@Ronen\_Levi](https://www.ruby-forum.com/u/Ronen_Levi)\
**Post date:** [May 13, 2006, 5:45pm UTC](https://www.ruby-forum.com/t/ajax-checkbox-using-rails/60422/6 "2006-05-13T17:45:44Z")

</div>

Adam Holt wrote:

> correct me if im wrong here like, but wouldnt you just set the frequency  
> to 0, hence making it event based and doing what you want when the  
> checkbox is clicked?
> 
> like i said correct me if im wrong, but it seems pretty self-explanitory  
> in the docs

Oops, didn’t notice the statement that 0 will take a different approach.  
Thanks - I’ll try that.
