Reputation: 1255
Example:
How can I ask the user for their gender
with a select_tag
, and then pass the value through a link?
HTML.ERB
<%= select_tag "gender", "<option value='male'>Male</option><option value='female'>Female</option>".html_safe %>
<%= link_to "Gender Evaluation", gender_eval_path(info: {gender: params[:gender]} %>
Upvotes: 1
Views: 1198
Reputation: 2289
You need to add on:change
event listener to your select tag, and in according function replace href
attribute for your link.
example:
assume your select tag has class gender-select
and link submit-link
$(document).ready(function(){
$('.gender-select').on('change', function(){
$('.submit-link).attr('href', 'some_url/?gender'+ $('.gender-select').val();
})
})
Replace some_url
with real url
Upvotes: 1