I have taken an example wherein, using Ajax, the values of a second
combobox are populated by a change in the primary combobox. The code
is shown below.
I realise it will seem as though I am asking someone to write the code
for me, BUT, can someone please show me, by way of an example how to
amend my index.rhtml below to use, say a radio button group instead of
a combobox, wherein when you change the radio button group, the
secondary combobox is changed, without having to incorporate a submit
button?
I somehow need someone to kickstart me here with this, and I can
bootstrap the rest of what I am trying to do. Thanks. R. Vince
#in mycontroller:
def create_select
indArr=[“Nordic Skiing”, “Inline Skating”,“Tennis”,
“Triathlon”,“Road Racing”,“Figure Skating”,
“Weight Lifting”,“Speed Skating”,“Snowboarding”];
teamArr=[“Soccer”,“Basketball”,“Football”,“Hockey”,
“Baseball”,“Lacrosse”];
str="";
if params[:categories].index(‘Team’) != nil
render :partial => “options”, :locals => { :sports =>
teamArr,:sptype => “team”}
elsif params[:categories].index(‘Individual’) != nil
render :partial => “options”, :locals => { :sports =>
indArr, :sptype => “individual” }
else
str="
unknown";
render :text => str;
end
end
#index.rhtml:
<%= form_remote_tag(:update => “sel_con”,:url => {
:action => :create_select },
:position => “top”,:success => “$(‘sel_con’).innerHTML=’’” ) %>
Please select a sports category:
<%= select_tag “categories”,
“TeamIndividual” %>
<%= submit_tag “Show Sports” %>
<%= end_form_tag %>
#_options.rhtml:
<% sports.each do |sport| %> <%= sport %> <% end %>