# Radio buttons and AJAX

**URL:** <https://www.ruby-forum.com/t/radio-buttons-and-ajax/100794>\
**Category:** Rails\
**Created:** [August 1, 2006, 4:40am UTC](https://www.ruby-forum.com/t/radio-buttons-and-ajax/100794 "2006-08-01T04:40:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![brianzimmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6f9a4e/32.png) [@brianzimmer](https://www.ruby-forum.com/u/brianzimmer)\
**Post date:** [August 1, 2006, 4:40am UTC](https://www.ruby-forum.com/t/radio-buttons-and-ajax/100794/1 "2006-08-01T04:40:43Z")

</div>

Hi,

Here is what I would like:

2 radio buttons:

“yes” and  
“no”

There will be 2 containers:

Yes stuff

No stuff

What I want is whenever the “yes” radio button is selected, on the “yes”  
div should be made visible.

When the “no” radio button is clicked, I want only the “no” div visible.

I’ve had many shots, but nothing works.

I was using RJS, because more than one update is required. I have to  
make one appear and one disappear, which is 2 calls. This way you can  
toggle back and forth.

The problem is calling the template. I couldn’t find a way to do  
something like this that worked:

\<%= radio\_button “project”, “yes\_or\_no”, “1”, :onclick =\> :url { :action  
=\> “show\_yes” } %\>

Then I tried:

\<%=  
observe\_field(‘project\_yes\_or\_no\_1’,  
:url =\> { :action =\> “show\_yes”})  
%\>

This only works some of the time, and only once. Once the template is  
called it never works again (if I click back and forth between the radio  
buttons)

I’m sure the RJS template works ebcause I tried it with a  
link\_to\_remote.

I’m out of ideas…

Thanks in advance.

Have a great day,  
Brian

---

<div class="post-metadata">

**Author:** ![brianzimmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6f9a4e/32.png) [@brianzimmer](https://www.ruby-forum.com/u/brianzimmer)\
**Post date:** [August 1, 2006, 8:48am UTC](https://www.ruby-forum.com/t/radio-buttons-and-ajax/100794/2 "2006-08-01T08:48:11Z")

</div>

## Does the “yes” stuff and “no” stuff really require another server roundtrip? It might just be easier to serve them both and use Javascript to turn them on and off as appropriate. You don’t even have to set up observers if you don’t want to. A simple onclick= should get you to your js function.

View this message in context:  
[http://www.nabble.com/Radio-buttons-and-AJAX-tf2031230.html#a5589246](http://www.nabble.com/Radio-buttons-and-AJAX-tf2031230.html#a5589246)  
Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![brianzimmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6f9a4e/32.png) [@brianzimmer](https://www.ruby-forum.com/u/brianzimmer)\
**Post date:** [August 1, 2006, 5:23pm UTC](https://www.ruby-forum.com/t/radio-buttons-and-ajax/100794/3 "2006-08-01T17:23:30Z")

</div>

Hi Steve,

Thanks for the tip.

The reason I havn’t just used JS was I was hoping to use  
[script.aculo.us](http://script.aculo.us), but you can’t use more than one effect for every  
onclick can you?

Or should I just generate a Javascript function that runs both of these.

Brian

Steve R. wrote:

> ## Does the “yes” stuff and “no” stuff really require another server roundtrip? It might just be easier to serve them both and use Javascript to turn them on and off as appropriate. You don’t even have to set up observers if you don’t want to. A simple onclick= should get you to your js function.
> 
> View this message in context:  
> [http://www.nabble.com/Radio-buttons-and-AJAX-tf2031230.html#a5589246](http://www.nabble.com/Radio-buttons-and-AJAX-tf2031230.html#a5589246)  
> Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![brianzimmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6f9a4e/32.png) [@brianzimmer](https://www.ruby-forum.com/u/brianzimmer)\
**Post date:** [August 1, 2006, 5:33pm UTC](https://www.ruby-forum.com/t/radio-buttons-and-ajax/100794/4 "2006-08-01T17:33:55Z")

</div>

Look into queuing effects. You can use multiple effects, but I haven’t  
done  
it.

Brian Zimmer-2 wrote:

> The reason I havn’t just used JS was I was hoping to use  
> [script.aculo.us](http://script.aculo.us), but you can’t use more than one effect for every  
> onclick can you?
> 
> Or should I just generate a Javascript function that runs both of these.

–  
View this message in context:  
[http://www.nabble.com/Radio-buttons-and-AJAX-tf2031230.html#a5596934](http://www.nabble.com/Radio-buttons-and-AJAX-tf2031230.html#a5596934)  
Sent from the RubyOnRails Users forum at [Nabble.com](http://Nabble.com).
