0

I currently have the following:

    $( "#Coupon" ).keyup(function() {
    $(this).val (function () {
        return this.value.toUpperCase();
    })      
    var url = window.location.href;
    var addon = $('#voucher').val();
    $("#ApplyCoupon").attr('href', url + "&coupon=" + addon);

which checks a text field and then adds the content to a url variable to check if the coupon is vali the next time the page loads.

My issue is that if you check multiple coupons, it keeps adding &coupon=blah

Is there any way of just replacing the coupon variable in the URL instead of creating new ones?

Aravind
  • 40,391
  • 16
  • 91
  • 110
BN83
  • 902
  • 3
  • 9
  • 29
  • @RuslanOsmanov how would I integrate that with the possibility of there not being the coupon variable already? – BN83 Sep 28 '16 at 20:47
  • sorry, the link in my previous comment was not quite appropriate, so I removed the comment. But [this](http://stackoverflow.com/questions/7171099/how-to-replace-url-parameter-with-javascript-jquery) looks like your question. Look at [this](http://stackoverflow.com/questions/7171099/how-to-replace-url-parameter-with-javascript-jquery#answer-20420424) answer. – Ruslan Osmanov Sep 28 '16 at 21:13
  • Thanks bud, but where in there do I get my value from the text field? – BN83 Sep 28 '16 at 22:23
  • `$("#ApplyCoupon").attr('href', replaceUrlParam(url, "coupon", addon));` – Ruslan Osmanov Sep 29 '16 at 08:16

0 Answers0