Forum: Ruby on Rails Showing options on radio button click

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
39025a7f572d6fe464e1fe6be399ca3b?d=identicon&s=25 Mike Dershowitz (mdersh53)
on 2007-01-19 15:20
(Received via mailing list)
Hello:

I have four radio buttons, each mutually exclusive.  I want to show a
div area somewhere else on the page when one of these radio buttons is
clicked.  I know how to do that in HTML - how do I do that in rails?
Here's one of my radio buttons:

<%= f.radio_button (:goaltype_id, 1) %>&nbsp;&nbsp;One-Time<br>

Thank you very much in advance!

Mike
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2007-01-19 16:25
(Received via mailing list)
Hi Mike,

Miked wrote:

> I want to show a div area somewhere else on the page when one of these
> radio buttons is clicked.

If you're talking about an Ajax-style update, as a first step, you
should
take a look at the form types that do that (i.e., submit using
XMLHttpRequest).  From there, updating a specific div on a page is
pretty
much a slam dunk using RJS.  I strongly recommend Cody Fauser's RJS
tutorial
on O'Reilly to get your feet wet in that area.  Best $10 you'll spend on
learning Rails.

hth,
Bill
39025a7f572d6fe464e1fe6be399ca3b?d=identicon&s=25 Mike Dershowitz (mdersh53)
on 2007-01-19 16:52
(Received via mailing list)
Hi Bill:

Thanks so much for your reply.  I was looking into the XMLHttpRequest
but I'm not finding in the rails api.  I definitely want to use the
ajax method.  I've only seen it attached to a submit tag though - can I
use it with a radio button as well?   Definitely something I want to
do.  I'm also going to use that book - it looks great, but no time for
that until the weekend!

So here's the code:

<% form_remote_tag :url => { :action => :goaltype, :id => product } do
%>
  <%= f.radio_button ("Goal", "radio", "onetime")
%>&nbsp;&nbsp;One-Time<br>
<% end %>

And then the RJS code:

page.replace_html("goaltype" , :partial => "goal_type")

But what happens in the controller method, since all I really want it
to do is render the partial?

Thanks again.

Mike
This topic is locked and can not be replied to.