How to use onsubmit() to show a confirmation if there are multiple submit buttons on the same form?
forms, html, onsubmit
Solution
<form method='post'>
<input type='submit' name='undo' value='Undo' onclick="return confirm('Are you sure you want to rollback deletion of candidate table?')"/>
<input type='submit' name='no' value='No' onclick="return confirm('Are you sure you want to commit delete and go back?')"/>
</form>
Worked fine. just changed `onsubmit()` to `onclick()`. as the function of both in this situation is same.
Problem
``` <form onsubmit="return confirm('Are you sure you want to rollback deletion of candidate table?')"> <input type='submit' name='delete' value='Undo' /> <input type='submit' name='no' value='No' /> ``` when the user clicks on second submit button i.e `No` i want to display the confirmation dialogue as "Are you sure you want to commit the transaction."
Related problems
- How can I get the button that caused the submit from the form submit event?
- How To Determine Which Submit Button Was Pressed, Form onSubmit Event, Without jQuery
- Two submit buttons in one form
- HTML form with two submit buttons and two "target" attributes
- Javascript onsubmit with form with multiple submits buttons