I have this link:
<p id="accept-favor"><a title="Accept this Favor" href="?wp_accept_favor=<?php comment_ID(); ?>">Accept this Favor</a></p>
I want to show a JavaScript alert box when a user clicks it saying: "Are you sure you would like to accept this reply as your favor?" with two buttons one saying "Yes" which will allow the function to run and the other saying "No" which will just cancel the postback and keep the user on the page.
How would I do this? Thanks :)
Syntax. window. confirm("sometext"); The window.
Alert box is used if we want the information comes through to the user. Confirm box is used if we want the user to verify or accept something. 2. You need to click “OK” to proceed when an alert box pops up.
The confirm() method displays a dialog box with a message, an OK button, and a Cancel button. The confirm() method returns true if the user clicked "OK", otherwise false .
A confirmation dialog box is mostly used to take user's consent on any option. It displays a dialog box with two buttons: OK and Cancel. If the user clicks on the OK button, the window method confirm() will return true. If the user clicks on the Cancel button, then confirm() returns false.
You can easily do it with a confirm onclick:
<p id="accept-favor"><a title="Accept this Favor" href="?wp_accept_favor=<?php comment_ID(); ?>" onclick="return confirm('Are you sure you would like to accept this reply as your favor?');" >Accept this Favor</a></p>
Though this will say OK/Cancel instead of Yes/No. If you really want Yes/No, you'll have to use a custom dialog.
You can write onclick="return confirm('Are you sure?');"
.
The confirm
function shows an OK / Cancel dialog and returns true
if the user clicked OK.return
ing false
from an onclick
handler will cancel the default action of the click.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With