Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add confirmation dialog to a submit button in html5 form?

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 select Yes or No 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!

like image 427
jartymcfly Avatar asked Aug 12 '15 11:08

jartymcfly


1 Answers

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>
like image 158
Akki619 Avatar answered Oct 09 '22 07:10

Akki619