observe field & javascript

Hi

How I can change this:

<%= radio_button("response_item", id, 1) %><%= h(imitem.grpname) %><br/

<a href="#" onclick="showdesc('<%= h(imitem.id) %>');">Help</a>

to work on radio button selection to call that same showdesc
javascript ? ie. I want to embed that javascript
inside of radio button so that once it is selected (clicked) it will
launch javascript call to showdesc call.

This works ok

<%= radio_button("response_item", id, 1, :onchange => "showdesc('4')")
%>

but now how can i replace value=4 with db id ?

<% for imitem in @imitems %>
<%= radio_button("response_item", id, 1, :onchange => "showdesc('4')")
%><%= h(imitem.grpname) %><br/>
<% end %>

I tried this one:

<%= radio_button("response_item", id, 1, :onchange => "showdesc('<%=
h(imitem.id) %>')") %>

but this throws an error:

compile error
/usr/local/webhome/mdm/app/views/imitems/showgroup.html.erb:11: syntax
error, unexpected tCONSTANT, expecting ')'
_erbout.concat(( submit_tag 'Next' ).to_s); _erbout.concat "\n"
                                 ^
/usr/local/webhome/mdm/app/views/imitems/showgroup.html.erb:11:
unterminated string meets end of file
/usr/local/webhome/mdm/app/views/imitems/showgroup.html.erb:11: syntax
error, unexpected $end, expecting ')'

This works ok

<%= radio_button("response_item", id, 1, :onchange => "showdesc('4')")
%>

but now how can i replace value=4 with db id ?

<% for imitem in @imitems %>
<%= radio_button("response_item", id, 1, :onchange => "showdesc('4')")
%><%= h(imitem.grpname) %><br/>
<% end %>

I tried this one:

<%= radio_button("response_item", id, 1, :onchange => "showdesc('<%=
h(imitem.id) %>')") %>

At this point it's just regular ruby (ie not an erb thingy) so

<%= radio_button("response_item", id, 1, :onchange =>
"showdesc('#{h(imitem.id)}')") %>

Should do the trick

Fred

Hi

Thanks for this one. One more thing.

<%= radio_button :imitem, :id, imitem.id, :id => "id", onchange =>
"showdesc()" %> <%= h(imitem.grpname) %><br/>
<%= radio_button("id", id, 1, :onchange =>
"showdesc('#{h(imitem.id)}')") %> <%= h(imitem.grpname) %><br/>

What about 1st line. It does not like onchange setting in there. Now
if I use 2nd line I get strange HTML code like this:

<input id="id_-607895668_1" name="id[-607895668]"
onchange="showdesc('4')" type="radio" value="1" /> demo<br/>

I would like this to be just

<input id="1" name="id" onchange="showdesc('4')" type="radio"
value="1" /> demo<br/>

ok I found the answer.

It needs to be like this:

<%= radio_button :imitem, :id, imitem.id, :id => "id", :onchange =>
"showdesc ('#{h(imitem.id)}')" %> <%= h(imitem.grpname) %><br/>