Topic: How to add a submit button to link drop down menu to controller

Hi, I want to link the selections from a drop down menu in my view to a controller action. Here's the code for my view:

 
<select>
<option><%= link_to "option A", :controller => "scriptrunner", :action => "runoptionA" %></option>
<option><%= link_to "option B", :controller => "scriptrunner", :action => "runoptionB" %></option>
<option><%= link_to "option C", :controller => "scriptrunner", :action => "runoptionC" %></option>
</select>

Right now when I select an option from the drop down menu, nothing is called in my controller. Is there a way to add a "GO" button, so after I select something from the menu, I can click the GO button and it will call the corresponding action in my controller?

Last edited by helpmepleaz (2012-07-20 16:14:24)

Re: How to add a submit button to link drop down menu to controller

try doing a onchange event and call a js function to take you there

view

= f.collection_select(:field_name,dd_values_from_helper, :id, :id, {:prompt => true}, {  onchange: 'js_function(this.value)'})

helper

 def dd_values_from_helper                                                                                                                           
    [                                                                                                                                        
      ['key', 'Val'],                                                                                                                 
      ['1', 'C'],                                                                                                              
      ['2', 'B'],                                                                                                                    
      ['3', 'A']                                                                                                              
    ]                                                                                                                                        
                                                                                                                                             
 end