ragrim Posted March 19, 2012 Share Posted March 19, 2012 Hi, I have a website that has cart and checkout and im rying to submit a form after i have a javascript popup asking to confirm order submit and clear cart, my form has 3 differant buttons and based on which button the form is submitted with the page does differant things, i just cant seem to get it to work as javascript tends to just "submit" the form not submit it by the id/name of the button i tried to submit with. heres my code. this is the form, ive cut alot of code out as its about 100 lines long <form id="order" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <a href="#" class="linkButton" onclick="clear_confirm()">Empty Cart</a> <input type="submit" class="formButton" name="update" value="Update Cart" /> <input type="submit" onclick="order_confirm()" value="Place Order" name="place_order" class="formButton" /> </form> heres the javascript function clear_confirm() { var r=confirm("Are you sure you want to empty the cart?") if (r==true) { window.location="index.php?location=cart.php&action=empty"; } else { } } function order_confirm() { var r=confirm("Are you sure you want to place the order") if (r==true) { document.forms["order"].submit(); } else { } } the clear and update work fine because the clear redirects to a new page, and the update self submits without going via javascript, but when i click on order confirm the java popup appears for confirmation but the page doesnt get submitted, when the page is submitted via order_confirm it should pick up this part if(isset($_POST['place_order'])) { echo "place order"; } am i missing something in the javascript to make it submit the form? thanks in advance Link to comment https://forums.phpfreaks.com/topic/259235-submitting-form-after-javascript-validate/ Share on other sites More sharing options...
shaiang Posted March 19, 2012 Share Posted March 19, 2012 Hi, You need to prevent the form submission. Javascript have a function ready for you. https://developer.mozilla.org/en/DOM/event.preventDefault Link to comment https://forums.phpfreaks.com/topic/259235-submitting-form-after-javascript-validate/#findComment-1328965 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.