I have a dropdown in haml view:
= collection_select(:vehicle_part, :service, Inventory.all, :id, :title, {}, {id: 'line_item', class: 'line_item', :onchange => "{my_function(this);}"})
It produces following HTML (for those who dont know haml)
<select class="line_item" id="line_item" name="vehicle_part[service]" onchange="{my_function(this);}">
<option value="1">first line</option>
<option value="2">second line</option>
</select>
And my javascript looks like:
try 1
$(document).ready(function () {
$( ".line_item" ).change(function() {
console.log( "Handler for .change() called." );
});
});
try 2
$(document).ready(function () {
my_function(value) {
console.log( "Handler for .change() called." );
});
});
I don't know why this is not working as everything seems fine.
Any help what i am doing wrong?
Forgot to mention: Does this work with bootstrap-modal? I am working in bootstrap-modal
Solution All I was doing wrong was not refreshing my page, how fool of me just thought that by loading modal will refresh the page.
onchangeattribute is not valid javascript