Forum: Ruby on Rails How to show div with radio button onclick

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.
F677fa685a2cfe8aff31f161062db3d3?d=identicon&s=25 David (Guest)
on 2009-02-17 05:47
(Received via mailing list)
I am trying to get a div to show when a radio button is clicked but
the problem is that the div is dynamically named.  I am using the
normal html for a radio button:

<input type="radio" name="edit_option" checked="checked"
value="this_appt">

Because observe field does not work well with radio buttons.  I have
tried adding an onclick with the div id:

<input type="radio" name="edit_option" checked="checked"
value="this_appt" onclick =
"$('edit_appt_frequency_#{@appt_to_edit.id}').show()">

But the #{@appt_to_edit.id} does not get rendered and I have had a lot
trouble figuring out how to do this.  I think I need to use some sort
of inline RJS?  Im not sure, does anyone have any ideas?
Ea52242ae25d195415cd9ef31db72aeb?d=identicon&s=25 Felix (Guest)
on 2009-02-17 10:22
(Received via mailing list)
<input type="radio" name="edit_option" checked="checked"
value="this_appt" onclick =
"$('edit_appt_frequency_<%=@appt_to_edit.id%>').show()">

this should do it. You are inside HTML code and not inside a ruby
string, so the #{} syntax won't work. Instead you have to use the Erb
sequence <%= %>
This topic is locked and can not be replied to.