Jump to content

Submitting form after javascript validate


ragrim

Recommended Posts

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.