<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."
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.
yes, multiple submit buttons can include in the html form. One simple example is given below.
One of the best way is using an input with hidden type , then on clicking button append value to that input and get that value in request params in controller side . And then using if and else condition run your query.
<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.
You could bind to onclick instead of onsubmit - see below.
<script>
function submitForm() {
return confirm('Rollback deletion of candidate table?');
}
<script>
<form>
<input type='submit' onclick='submitForm()' name='delete' value='Undo' />
<input type='submit' onclick='submitForm()' name='no' value='No' />
</form>
Or alternately, using jQuery:
<script>
$(document).ready(function() {
$('form input[type=submit]').click(function() {
return confirm('Rollback deletion of candidate table?');
});
});
<script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With