The following function is only getting first index amount, while I need all the fields of amount, and find amount type in those fields
$("#payment_info").on("change", ".price", function() {
var amount = $(".amount").val();
var price = $(this).val();
var at = $(".amount_type").val();
if (at === "Percentage"){
$('.amount').val(amount * 100 / price);
}
console.log("hello",price,amount, at);
}
);
#payment_info
.card.mt-3
.card-header
h5 Payment Information
.card-body
.row
-if company.id == 11
.col-md-3
= f.input :monthly_rent, label: 'Monthly Rent', input_html: { class: 'maskme', value: "#{contract.monthly_rent unless contract.nil?}" }
.col-sm-3
-if contract.new_record?
= f.input :price, label:'Total Rent', required:true, input_html:{class:'maskme',class:"price", value: "#{unit.market_rent unless unit.nil?}"}
-else
= f.input :price, label:'Total Rent', required:true, input_html:{class:'maskme',class:"price", value: "#{contract.price unless contract.nil?}"}
.col-sm-3
amount_input , and amount_type input
.atype.col
= f.input :amount_type ,as: :hidden , input_html:{class:"amount_type"}
= f.input :amount,label: f.index == 0 ? 'Amount' : false, placeholder: 'Amount', disabled: disable, input_html:{class:'amount maskme',class:"amount"}
CodePudding user response:
You can you document.getElementsByClassName()
to get all elements and apply loop on it.
var items = document.getElementsByClassName(className);
for (var i=0; i < items.length; i ) {
items[i].val(amount * 100 / price);
}
I hope this will help you.