0
Addition issue
https://code.sololearn.com/WZ1XwWHxYw34/# i have this code but i'm stucked trying to solve the last part of the program. My idea is that when the user click on the "Finish" button the page shows the total account. The problem is that in the function "sumar" declared 6 variables but if i don't create the 6 clones that function returns this error...Uncaught TypeError: Cannot read property 'value' of null Line: 52. somebody knows how to solve this??? please!!!
2 Answers
+ 1
Of coursŠµ it returns an error. You have hardcoded 6 purchases, no more, no less.
You should start from st1, not st and to calculate a total you should either make a loop, like
for(var i=1,i<=count,++i)
{
var subtotal = document.getElementById("st"+i);
total+= +subtotal.value;
}
Or you can just make all subtotals a class e.g. subtotal and then get all vubtotals by
var subtotals = document.getElementsByClassName("subtotal");
and then iterate the collection
for(var i=0;i<subtotals.length;++i)
{
total+=+subtotal[i].value;
}
You should also modify a multiply function: write one with argument and pass a order number of added form as argument
I've modified your code, take a look
https://code.sololearn.com/W5XW8eb5oN7z/?ref=app
0
Thanks A Lot....really