Answer the question
In order to leave comments, you need to log in
Why is the calculation not working correctly?
Hello.
I ran into a problem when writing a script, the price is not calculated correctly, why - I can’t understand.
Script https://jsfiddle.net/sLbuxf15/6/ (a lot of extra things, classes, etc. - I know, this is just part of the general code), but I think the essence is clear.
For example, when you click on Любой текст 1
- the price becomes 105 . But when you click on Любой текст 1
it again, the price becomes 95 , although it should go back to 100 ..
Please help me, where did I make a mistake
Answer the question
In order to leave comments, you need to log in
Greetings.
Because you get the value of "price" via data() and set via attr() ,
but data is cached and not auto-updated if you set via attr, so either set/get via data or via attr, or set at the same time and in attr and in data.
By the way, you also have this bug - if you click not on the labels but on the checkbox itself.
Fix both bugs: https://jsfiddle.net/sLbuxf15/45/
well, you clearly wrote the logic for this)) there are no errors in the code)
if(inputCheck) {
var str = prodprice - price; // при втором нажатии 100 - 5
} else {
var str = prodprice + price; // при первом нажатии 100 + 5
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question