Search code examples
javascripthtmlonclicksubmitconfirm

Using a div to confirm AND submit a form


I have the following code:

<div class="ui-button-submit" onclick="document.forms['appointment-form'].submit();"><img src="/laravel/public/img/icon-delete.png"><span class="ui-button-text"> Mass Delete</span></div>

In my form I have a few checkboxes which I can click and then hit this button (the above code) to submit and delete those records. The thing is, I need to have a confirmation message in the above code, so it asks for a confirmation before submitting the form. Any ideas?


Solution

  • You need to show confirm box before submitting the form. So , first change the form submit method call, when you click on Mass Delete button show Confirm dialogue using JavaScript, then user click on OK or YES button then submit the form(call your method document.forms['appointment-form'].submit()).