I'm trying to add a coupon Code system method to my existing form, the only problem is that the form already has a form action.
<form id="apply" name="apply" method="post" action="<?php echo $editFormAction; ?>">
I have searched high and low for a solution and stumbled on a solution of a combination of AJAX java script/ jquery.
In my code i echo the discount value from the database which will be used for the math. I also echo the coupon code itself and the total to be reduced.
<tr>
<td class="detailnoborder"><label for="Dicount_code">Enter Code for Discount:</label> </td>
<td class="detailnoborder1">
<input type="text" tabindex="33" id="coupon" name="coupon_id" size="10"/>
<input type="text" tabindex="10" id="T_cost" name="T_cost" size="5" value="<?php echo $row_rsMembershipTypes['Cost']?>"/>
<input type="text" tabindex="10" id="Discount" name="Discount" size="5" value="<?php echo $row_rsdiscount['discount']?>"/>
<input type="text" tabindex="10" id="D_amount" name="D_amount" size="5" value="<?php echo $row_rsdiscount['D_Cost']?>"/>
<input type="button" id="Check" value="Check" onclick="chk_discount()" type="submit"/>
</tr>
I originally had a function named chk_discount of which i was completely unsure of what i was doing.
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
$("#Check").click(function() {
$.ajax({
type: "POST",
url: 'ajax.php',
data:{coupon: $('#coupon').val(), },
success:function(data) {
if (data != ''){
//display error message however you would like
}
}
});
}
</script>
further research i decided to create a function that connects to my ajax.php file which the php function will be in.. to be honest im kinder confused.
<?php
if(isset($_POST['coupon'] == HXAR1){
$D_Cost - $Cost;
}
return ($Cost);
?>
Ideally when I post to ajax I would like to do that math for subtracting one database value with the other to give a total cost to then be sent to Paypal on submission but the check discount will be done before..
I'm not asking for anyone to do this for me but some help would be deeply appreciated.