40π
β
I believe you want to use confirm()
<script type="text/javascript">
function clicked() {
if (confirm('Do you want to submit?')) {
yourformelement.submit();
} else {
return false;
}
}
</script>
π€DaneoShiga
217π
The most compact version:
<input type="submit" onclick="return confirm('Are you sure?')" />
The key thing to note is the return
β
Because there are many ways to skin a cat, here is another alternate method:
HTML:
<input type="submit" onclick="clicked(event)" />
Javascript:
<script>
function clicked(e)
{
if(!confirm('Are you sure?')) {
e.preventDefault();
}
}
</script>
π€Isaac
- [Django]-You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application
- [Django]-Django Password Generator
- [Django]-How to check Django version
7π
Use window.confirm()
instead of window.alert()
.
HTML:
<input type="submit" onclick="return clicked();" value="Button" />
JavaScript:
function clicked() {
return confirm('clicked');
}
π€Matt Ball
- [Django]-New url format in Django 1.9
- [Django]-How does django handle multiple memcached servers?
- [Django]-Django Rest Framework remove csrf
4π
For a Django form, you can add the confirmation dialog inside the form tag:
<form action="{% url 'delete' %}" method="POST" onsubmit="return confirm ('Are you sure?')">
π€user3693317
- [Django]-How to get an ImageField URL within a template?
- [Django]-How to iterate through dictionary in a dictionary in django template?
- [Django]-Redirect to Next after login in Django
3π
<script type='text/javascript'>
function foo() {
var user_choice = window.confirm('Would you like to continue?');
if(user_choice==true) {
window.location='your url'; // you can also use element.submit() if your input type='submit'
} else {
return false;
}
}
</script>
<input type="button" onClick="foo()" value="save">
π€Manjunath
- [Django]-Mac OS X β EnvironmentError: mysql_config not found
- [Django]-Django-taggit β how do I display the tags related to each record
- [Django]-How do I run tests against a Django data migration?
2π
Another option that you can use is:
onclick="if(confirm('Do you have sure ?')){}else{return false;};"
using this function on submit button you will get what you expect.
π€Tiego Araujo
- [Django]-How to call function that takes an argument in a Django template?
- [Django]-Django-celery: No result backend configured
- [Django]-How can I upgrade specific packages using pip and a requirements file?
0π
You can use onclick
in the submit button:
<button type="submit" onclick="return confirm('Are you sure?');"/>Delete</button>
You can also use onsubmit
in the form:
<form action="/" method="POST" onsubmit="return confirm('Are you sure?');">
<button type="submit"/>Delete</button>
</form>
π€doncadavona
- [Django]-Django: Implementing a Form within a generic DetailView
- [Django]-Unable to perform collectstatic
- [Django]-Get Timezone from City in Python/Django
0π
Add the onClick function to the button
<input type="submit" onclick="return confirm('Are you sure?')" />
π€Alanso Mathew
- [Django]-Where is a good place to work on accounts/profile in Django with the Django registration app?
- [Django]-How to have a Python script for a Django app that accesses models without using the manage.py shell?
- [Django]-How to redirect with post data (Django)
Source:stackexchange.com