Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 896
Richard Avatar asked Mar 22 '13 21:03

Richard


People also ask

Can we have 2 submit buttons in a form?

yes, multiple submit buttons can include in the html form. One simple example is given below.

How do you handle multiple submit buttons in the same form?

Create another button with type submit. Also add a 'formaction' attribute to this button and give it the value of the secondary URL where you want to send the form-data when this button is clicked. The formaction attribute will override the action attribute of the form and send the data to your desired location.

Which JS method shows two buttons OK and Cancel?

The confirm() function displays a popup message to the user with two buttons, OK and Cancel .

Which function is used for confirmation by dialog box?

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 .


1 Answers

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

like image 111
Carlos Blanco Avatar answered Sep 23 '22 08:09

Carlos Blanco