Reputation: 313
Now my case might be a bit weird. I have a select_tag, user has to select one value from the list I gave. I know how to retrieve the value they selected once they click on the submit. But now I would also like to display some info for the selected value BEFORE they click on submit, just when they select any value in the drop down list.
So is there any way to get the value after user selects but before user submits ?
E.g:
select_tag("a", options_for_select(my_option_list))
the param[:a]
will have the value just after user submits this. How can I get the value before they submit?
Upvotes: 1
Views: 2742
Reputation: 4879
You will need to use javascript/coffeescript for this. A sample of this might be something like this:
$(document).ready ->
$("#id_of_select_that_the_select_tag_generates").change ->
# do something
Put the above in app/assets/javascripts/some_file_name.js.coffee
Upvotes: 0
Reputation: 6263
It depends what you want to do but you could use javascript.
Check out the fiddle
<select id="my_select">
<option value="value 1">Option 1</option>
<option value="value 2">Option 2</option>
<option value="value 3">Option 3</option>
<option value="value 4">Option 4</option>
</select>
$(function(){
$('#my_select').on('change', function(){
alert('do soemthing ' + $(this).val());
});
});
Upvotes: 1