How can I add confirmation dialog to a submit button in html5 form?
28,502
Have onsubmit
attribute in your form tag like this if you just want a confirmation from user.
https://jsfiddle.net/yetn60ja/
<form id="id"
method="POST" action="/y/b/"
enctype="multipart/form-data"
onsubmit="return confirm('Do you really want to submit the form?');"
>
<input class="btn btn-primary"
type="submit" name="submit" value="A"
/>
</form>
EDIT: Or try below code
<form id="id"
method="POST" action="/y/b/"
enctype="multipart/form-data"
>
<input class="btn btn-primary"
type="submit" name="submit" value="A"
onclick="return confirm('Do you really want to submit the form?');"
/>
</form>
Author by
jartymcfly
Updated on May 01, 2020Comments
-
jartymcfly about 4 years
I am creating an application in
django
and I have the next problem: I have a form in html with a submit button, but I want to show a confirmation dialog to selectYes
orNo
before processing the information. How could I do it?This is my form code:
<form id="id" method="post" action="/y/b/" enctype="multipart/form-data"> {% csrf_token %} {{ form.as_p }} <input class="btn btn-primary" type="submit" name="submit" value="A" /> </form>
Thank you so much!