function counting(result) {
document.getElementById("total").value= result;
}
counting(0);
function totalSumField () {
let inp = document.querySelectorAll("#allInp > .inp");
let result=0;
for(let i=0;i<inp.length;i++){
let price=inp[i].getElementsByClassName("price")[0].value;
let quantity=inp[i].getElementsByClassName("quantity")[0].value;
inp[i].getElementsByClassName("totalSumField")[0].value=(price*quantity);
}
function totalSum () {
let inp = document.querySelectorAll("#allInp > .inp");
let result=0;
for(let i=0;i<inp.length;i++){
let price=inp[i].getElementsByClassName("price")[0].value;
let quantity=inp[i].getElementsByClassName("quantity")[0].value;
[0].value;
result+=(quantity*price);
}
counting(result)
totalSumField()
}
i want to when the user write something to the quantity and price fields then quantity*price and show the result in the total price field before saving the form , i know i should use onkeyup="totalSum()" to the quantity and price fields but in django i dont know where should i use the onKeyup attribute to the fields !?
thank you for helping please
hi there i'm trying to add onKeyup() event to my django inlineformset fields , but i dont know how to achieve it this
this is my models.py
and this is my template
and my js code to show the total price
i want to when the user write something to the quantity and price fields then
quantity*price
and show the result in the total price field before saving the form , i know i should useonkeyup="totalSum()"
to thequantity
andprice
fields but in django i dont know where should i use theonKeyup
attribute to the fields !? thank you for helping please