Note that there are some explanatory texts on larger screens.

plurals
  1. POSend data to another function JQuery
    text
    copied!<p>I am trying to set up a coupon/promo/discount codes in my order form, however i cannot get the coupon amount to go to the updatePrices function.</p> <pre><code>function updateCoupon() { var coupon = $('#coupon').val(); if (coupon.length) { $('#couponContainer .checking').show(); $.ajax({ url: "/includes/pscript/coupon.php", data: {coupon: coupon}, dataType: 'json', type: 'POST', success: function(data) { if(typeof data.available != 'undefined' &amp;&amp; data.available == true) { coupon_discount = new Number(data.price.discount); $('#couponStatus').html('&lt;p&gt;'+data.status+'&lt;/p &gt; '); $('#couponContainer .checking').hide(); $('#couponStatus').show(); updatePrices(coupon_discount); } else { coupon_discount = 0; $('#coupon ').val(''); $('#couponContainer .checking').hide(); $('#couponStatus ').hide(); $('#couponStatus ').html(''); alert('Sorry this discount code is no long valid!'); } }, error: function() { coupon_discount = 0; $('#coupon ').val(''); $('#couponContainer .checking').hide(); $('#couponStatus ').hide(); $('#couponStatus ').html(''); alert('Sorry this discount code is no long valid!'); } }); } else { coupon_discount = 0; $('#coupon').val(''); $('#couponContainer.checking ').hide(); $('#couponStatus ').hide(); $('#couponStatus ').html(''); alert('Sorry this discount code is no long valid!'); } } </code></pre> <p>The above does work, and it receives the amount. Once it has the amount i would like it to send to updatePrices();</p> <pre><code>function updatePrices(a, coupon_discount) { var item_price = 0; var delivery_price = 0; var discounts = 0; if(coupon_discount != 0){ var coupon_discount = coupon_discount; alert('Coupon '+coupon_discount); } var product = $("[name='Product']").val(); ... if(coupon_discount != 0) { discounts += coupon_discount; } var total = (item_price + delivery_price - discounts); </code></pre> <p>}</p> <p>This is only part of the code. All i would like it to do is, updateCoupon gets the price sends it to updatePrices - if say a product was changed the coupon is removed and a message will appear to reapply.</p> <p>Problem currently: I am getting undefined in updatePrices() </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload