简体   繁体   中英

JS confirm() cancel button still submits form

I've created a confirmation box that does submit the form when "Ok" is clicked, however the form still submits when "Cancel" is clicked as well and I'd like that to stop, any help would be very much appreciated. See code below, and please let me know what else you may need from me, I'd be happy to post it.

function confirmation() {
    var r = confirm("Would you like to make a deposit?");
    if (r == true) {
        return true;
    } else {
        return false;
    }
}

And

<asp:Button ID="BtnApplyPayment" runat="server" TabIndex="750" Text="Apply &gt;&gt;"ValidationGroup ="vgPayment" OnClientClick ="confirmation();" />

You should maybe catch the submit event like this.

 <form onsubmit="return confirm('Would you like to make a deposit?')"> <input type="submit" value="go"> </form> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM