I've created a shopping cart which works well.
Im having a problem clearing the cart, i want to use javascript to do this.
I want to use a button so when pressed it asks the user to confirm if they want to clear it, and if ok is pressed it is cleared.
So i have created the php code to clear my cart:
if (isset($_GET['cmd']) && $_GET['cmd'] == "emptycart") {
unset($_SESSION["cart_array"]);
And when this is assigned to a link it clears the cart. For example:
<a href="cart.php?cmd=emptycart">Empty Cart</a>
However i want to change this to a button.
So far i have the following javascript code to give the validation but does not clear the cart.
<script language="javascript">
function clear_cart(){
if(confirm('Shopping cart will be cleared. Continue?')){
document.form1.command.value='emptycart';
document.form1.submit();
}
}
</script>
The button:
<input type="button" value="Clear Cart" onclick="clear_cart()">
So my question is how do i get this to clear using this button and with the use of javascript or AJAX.
Thanks!