Hi i am currently using Collection_select like so , and as you can see its working properly but i want to make it, so that when i pick 1 item from the Item field that the data from my database , bought price and sold price would automatically be added into the textfields like in the example below.
but as to how i can do it, remains a mystery to me, can anybody help me with this and thanks! any help will be helpful! and thanks again!
the code that i used
<%= form_for(@sale) do |f| %>
<% if @sale.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@sale.errors.count, "error") %> prohibited this sale from being saved:</h2>
<ul>
<% @sale.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :item_id %><br>
<%= collection_select( :sale, :item_id, Item.all, :id, :name, {} ) %>
</div>
<div class="field">
<%= f.label :bought %><br>
<%= f.text_field :bought %>
</div>
<div class="field">
<%= f.label :sold %><br>
<%= f.text_field :sold %>
</div>
<div class="field">
<%= f.label :number %><br>
<%= f.number_field :number %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>