Hi guys im new to coding and im trying to add a coupon code field to my form in contact form 7 in wordpress, the problem I had is that i assigned a value for adult and kid, and depending on the amount of each it would return the total value, but it was returning the value of both adult and kid even if there was only 1 adult and 0 kid, so i found a fix by using this code subtotal = $("#subtotal").val(Number($("#adult").val()*35) + Number($("#kid").val()*18.40)); ,but know the couponcode field does not work, I would really appreciate your help, thanks.
This is the link to the form im working on.
The code im using.
jQuery(document).ready(function () {
//alert("Welcome");
var adult;
var kid;
var subtotal;
var total;
var couponcode;
jQuery("#adult, #kid").on("change", function () {
adult = this.value;
kid = this.value;
subtotal = $("#subtotal").val(
Number($("#adult").val() * 35) + Number($("#kid").val() * 18.4)
);
jQuery("#subtotal").val(subtotal.toFixed(2));
});
jQuery('input[name="couponcode"]').on("input keydown keyup", function (e) {
let couponcode = jQuery('input[name="couponcode"]').val().trim();
if (couponcode == "CCPPF") {
total = subtotal * 0.1;
jQuery("#total").val(total.toFixed(2));
}
});
});
Looking at your site reference, which has changed since my previous comment:
The reference to: jQuery("#total"), should be: jQuery("#totcalc")