I’m fairly new to JavaScript and am trying to write some code that lists three price options in a form, as checkboxes. If both of the first two are selected, I want the total price to drop by a certain amount.
My code is based on the code in this question:
Javascript checkboxes incorrect calculating
They reset the base value by a date variable. I assume that if I have a function that sets the base to a negative value if those two boxes are checked, that would achieve what I want. I’d also like the output to have an additional tag of ‘save (x) per month’ when this happens.
However I’m not sure how to go about relating the variable to the checkboxes.. do I need to use jquery as per how to change the value of a variable based on a select option:selected?
I’m assuming you are modifying your
recalculate()function from your earlier question. In that function, after you get your sum, add this to apply the discount:To write the message to your output, modify your
$("#output").html(sum)code to this: