Hi all,
Hope everyone has had a good week.....
My question comes in the form of I'm trying to get one figure the minus another figure. I'm using jQuery for this has I haven't got around to re-learning Vue just yet.
So lets say I have a figure of $27.99 then the customer applies a discount code of $5 that would equal $22.99 right?
Based on this (slightly messy hack) where am I going wrong?
$("#success").hide();
$("#error").hide();
var totalPrice = $("#totalPricePHP").text().replace("£", "").replace(".", "");
$("#validateCoupon").click(function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: '/validateCoupon/' + $('#coupon').val(),
data: {
code: $('#coupon').val()
},
success: function(data) {
console.log("Total: " + totalPrice);
console.log("Discount: " + data.amount);
if (data != '') {
$("#error").hide();
$("#totalPricePHP").hide();
$("#success").show().append("Great! £" + data.amount + " has been deducted.");
$("#success:disabled");
$("#totalPrice").html("£" + Math.round(data.amount - totalPrice));
}
},
error: function(data){
console.log(data);
$("#success").hide();
$("#error").show().append("Something was wrong with the coupon you entered.");
}
});
});
Idea's to improve this messy lot, will also be grateful, but just looking to get it working and formatting in a currency correctly first.