Reputation: 3048
I have a select tag in my rails app, and i want to call showSubTypes function function onchange event
<%= f.select :type, RequestType.all.collect {
|p| [p.typeName, p.id] }, {include_blank: true },
:onchange => 'showSubTypes()' %>
Here i want to pass p.id parameter into my showSubtypes function. But i do not know how to do that in rails.
Upvotes: 1
Views: 1145
Reputation: 77482
For example you can add in application.js
this code
$(function () {
// specify id or class for your select tag
$('select').on('change', function () {
console.log($(this).val()); // get option value
console.log($(this).text()); // get option text
showSubTypes($(this).val());
});
});
If you use jQuery you don't need use inline events
And in your template
<%= f.select :type, RequestType.all.collect {|p| [p.typeName, p.id]}, {include_blank: true } %>
Upvotes: 1