How to use onsubmit() to show a confirmation if there are multiple submit buttons on the same form?

RatDon picture RatDon · Aug 4, 2013 · Viewed 73.4k times · Source
<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."

Answer

RatDon picture RatDon · Aug 4, 2013
<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.