简体   繁体   中英

onclick Button Event with Confirm Dialog Box

This code is from a PHP software (using Smarty template engine) and it works:

    <input type=\"button\" class=\"btn btn-primary\" value=\"{$LANG["phrase_send_email"]}\" onclick=\"ms.edit_submission_page_send_email($submission_id); this.disabled=true;\" />";

A user clicks on the button and the software will:

  • send an email to the recipient
  • the button is disabled to prevent multiple emails being sent by accidentally clicking it more than once

I want it to do more: adding a popup confirmation dialog box. The purpose is to remind the human to do something first by reading the text message in the confirmation dialog box before sending an email.

So if the user clicks OK:

  • execute button function
  • disables button

or if the user cancels:

  • dialog box cancels and no email function executes. Return to screen.

There are plenty of JavaScript if else/confirm examples. But I'm new to JavaScript and have no idea how ms.edit_submission_page_send_email($submission_id) fits into the JavaScript world.

How would one put all of this into a JavaScript function?

Try this way.

<input type=\"button\" class=\"btn btn-primary\" value=\"{$LANG["phrase_send_email"]}\" onclick=\"{literal}return checkValidMailSend(this, $submission_id){/literal}\" />";

{literal}
<script>
function checkValidMailSend(this, submissionid) {
    if(!confirm("Are you sure to send mail?")) {
        return false;
    }
    else {
        ms.edit_submission_page_send_email(submissionid);
        this.disabled=true;
    }
}
</script>
{/literal}

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