I have a form in HTML to apply a Discount Coupon to the current shopping cart. I would like the user to just press APPLY (after entering the coupon code) and then not refresh the page to run some PHP code, so it calculates the corresponding discount.
Here is my form:
<form action=""> <input type="text" name="couponCode"> <input type="submit" value="Apply"> </form>
PHP to run:
if (isset($_REQUEST['couponCode']) && $_REQUEST['couponCode']!='') { $couponCode = $_REQUEST['couponCode']; if ($couponCode == "TEST1") { $discount=0.2; } }
How to do this using javascript?
source share