0

Try adding a calculator function for a promo code.

Demo code: http://apollo.us/promo/

JS code: http://apollo.us/promo/js/webEstimator.js

When you write promo code - test or test1 - final TOTAL price change.

The final total price is displayed on the : var $total = $(".W_E-total"); // show total price

Promocode function:

var $finalprice = $('.W_E-total').val();
var promocode;

$('#update').click(function() {
  promocode = $('#promocode').val();
  total = $('.W_E-total').val();

  finalprice = total;
  if ((promocode == 'test') || (promocode == 'test1')) {
   finalprice = +finalprice * 0.9;
  } else if (promocode.length < 1) {
   finalprice = +finalprice * 1;
  } else {
   alert("Invalid Promo Code");
   finalprice = 0;
  }
  $('.W_E-total').val(finalprice);
}); 

You pressing the button "Update TOTAL Price" - TOTAL be changed.

What needs to change in the code?

Thank you! Happy Holidays!

DelMar
  • 3
  • 1
  • 4

1 Answers1

0

This should do it:

var $total = $("#W_E-total"); // show total price

/* PROMO CODE */
var max_price = parseInt($('#W_E-total').val()),
    finalprice = max_price;
var promocode;

$('#update').click(function () {
    promocode = $('#promocode').val();

    if ((promocode == 'test') || (promocode == 'test1')) {
        finalprice = max_price * 0.9;
    } else if (promocode.length < 1) {
        finalprice = max_price;
    } else {
        alert("Invalid Promo Code");
        finalprice = 0;  //Shouldn't this be maxprice too?
    }
    $total.val(finalprice);
});
Johan Karlsson
  • 6,219
  • 1
  • 16
  • 27
  • Not working :( I put your code. Demo: http://apollo.us/promo/js/webEstimator.js Site: http://apollo.us/promo/ – DelMar Dec 22 '14 at 12:51