Kiki
Kiki

Reputation: 333

Dialog box when "Place Order" clicked

I want to display a dialog box when my customer click "Place Order" on checkout page for last confirmation. I added following code

footer.php

<script type="text/javascript">
  function lastConfirm() {
   
     var r = confirm("Are you sure?");

     if( r == true){
        return true;
     } else {
        return false;
     }
   }
</script>

and I added onsubmit="lastConfirm()" inside form tag like below

form-checkout.php

<form name="checkout" method="post" class="checkout woocommerce-checkout" enctype="multipart/form-data" onsubmit="return lastConfirm()">

The dialog box pops up when I click "Place Order", but the order will be processed anyway whether I choose "OK" or "Cancel".

I want the order processed only when I click "OK". How could I accomplish this?


EDIT - The working answer form me is:

<form method="post" onsubmit="return lastConfirm()">

I just needed to remove some (well...most) attributes.

Upvotes: 3

Views: 1023

Answers (2)

Patharraj
Patharraj

Reputation: 51

call your function inside the condition was true.

Upvotes: 1

kirellos sahdar
kirellos sahdar

Reputation: 46

remove the elements from Form Tag and place only the javascript function in onsubmit

<form onsubmit="return lastConfirm()">

basically the code showing in your question works any way to show the js function

but you should prevent the form from proceed to its method or any other parameter that will effect on the page to refresh sense you want to do every thing with js function

Upvotes: 2

Related Questions