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

Richard picture Richard · Mar 22, 2013 · Viewed 68.8k times · Source

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!

Answer

Carlos Blanco picture Carlos Blanco · Mar 22, 2013

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