A client has a range of coupon codes that people can enter in the shopping
cart to receive a certain percentage off their order. It's based on their
subtotal in a range from 0 - $6000. He says that sometimes people willl
enter the max coupon code for a lower range order thinking that they'll get
the larger discount even though they don't qualify for that level.

I wrote a quick function to check the range, but it appears a bit clunky. I
know that many of you are really good at tweaking js to make it more fluid
and concise. Anyone have input on this one?

What it does is to first get their merch subtotal, and the coupon code
they've entered (if they entered one). It then creates the "correct" code
for their merch level. Finally it lowercases the code they entered, tests it
against the "right" code and replaces it (along with an alert message) if
the codes don't match. If the user enters no code then nothing should
happen.

function checkCoupon() {
        /* check the coupon code function */
        var curCoupon = $('#v_code').val();
        var st = parseInt($('#thesubtotal').html());
        if (st < 1499.99) {
                appcode = 'save10';
        } else if (st > 1499.99 && st < 1999.99) {
                appcode = 'save5freeship';
        } else if (st > 1999.99 && st < 2999.99) {
                appcode = 'save10freeship';
        } else if (st > 2999.99 && st < 5999.99) {
                appcode = 'save15freeship';
        } else if (st > 5999.99) {
                appcode = 'save20freeship';
        } else {
                appcode = 'what?';
        }
        if (curCoupon != '' && curCoupon.toLowerCase() != 
appcode.toLowerCase())  {
                alert('You have entered the incorrect coupon code for your 
merchandise
total. Your code has been updated.');
                $('#v_code').val(appcode);
        }
}



<!----------------//------
andy matthews
web developer
certified advanced coldfusion programmer
ICGLink, Inc.
[EMAIL PROTECTED]
615.370.1530 x737
--------------//--------->


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to