I have a form with selection input called units_system that can be metrical or imperial.
<%= form.select :units_system, [['metrical', id: 'metrical'], ['imperial', id: :imperial]], {prompt: 'Select units system'}, {class: "form-control", id: :item_units_system}%>
It is generate html
<select class="form-control" id="lot_units_system" name="lot[units_system]"><option value="">Select units system</option>
<option id="metrical" value="metrical">metrical</option>
<option id="imperial" value="imperial">imperial</option></select>
Depend of my choose I would like render different partials in <div id=”cargo_form”></div>
If I click on id=”metrical” I want to see text “METRICAL” in <div id=”cargo_form”></div>
.
So I put in my new.js.erb next jquery code:
$('#metrical').click(function(e) {
e.preventDefault();
$('#cargo_form').html('METRICAL');
});
But nothing gonna heppened. I don't see any result in <div id=”cargo_form”></div>
What I am doing wrong? Thanks for help!
question from:
https://stackoverflow.com/questions/65910406/how-to-use-jquery-click-method-with-form-select-in-ruby-on-rails 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…