Search code examples
javascriptjspconfirmonsubmit

Javascript How to use Confirm Dialog Box onSubmit with two submit buttons on JSP


My form currently has two submit buttons. One for Search and the other for a Mark Complete function. I need to show a confirm dialog box ONLY when the "Mark Complete" button is clicked to submit the form with that validation is passed. Is it possible to identify this? I currently have the below confirmComplete function:

function confirmComplete() {
alert("confirmComplete");
var answer=confirm("Are you sure you want to continue");
if (answer==true)
  {
    return true;
  }
else
  {
    return false;
  }
}

Any help would be appreciated!


Solution

  • Set the onclick attribute of the "Mark Complete" button to this

     onclick="return confirm('Are you sure you want to continue')" 
    

    and remove the confirmComplete function from the form