7👍
I’ve not used bootbox
, but assuming the x
value in the function is the boolean result of the popup, this should work:
<a href="/jobs/emp/del/?id={{ job.pk }}" class="btn deleteJob">
<i class="icon-trash"></i>
</a>
$('.deleteJob').click(function(e) {
e.preventDefault();
var $link = $(this);
bootbox.confirm("Are you Sure want to delete!", function (confirmation) {
confirmation && document.location.assign($link.attr('href'));
});
});
Note, you mention a for
loop – the jQuery code there does not need to be in a loop. That code will work for all instances of the .deleteJob
anchor element.
3👍
You can use preventDefault()
to stop the redirect;
$('.deleteJob').click(function(e) {
e.preventDefault();
if(confirm("Are you Sure want to delete!")) {
var link= $(this).find( $spans ).text();
document.location.href='/'+link+'/';}
}
});
I’m not sure about bootbox
so this is a jQuery
only solution
0👍
<script>
$('.deleteJob')each(function(){
var href = $(this).attr("href");
$(this).click(function(){
if(confirm("Are you sure you want to delete this job ?"))
{
document.location.href='/'+href+'/';}
}
});
});
</script>
maybe this could work if you don’t mind using the normal confirm window from the browser.
- [Django]-Django – multiplication and templates
- [Django]-Django Internationalization—compilemessages error:AttributeError: module 'locale' has no attribute 'normalize'
- [Django]-Apache + Django on Windows does not start
0👍
Is it working if you are using it outside of a loop? The problem looks like you are running into javascript closures problem, which basically means that functions assigned in loops will be overwritten the next time the loop is executed and thus the function onclick would be binded only on the last DOM that was parsed to it in the loop. In order to work around that move the onclick assignment to an external function that is called on every iteration of the loop (you probably need to parse.
Also is this valid jquery identifier?: $spans
Read about closures here.
- [Django]-Inconsistent SignatureDoesNotMatch Amazon S3 with django-pipeline, s3boto and storages
- [Django]-How to change the height of the parent div of a plotly_app iframe in python/django?
0👍
You must prevent the default action on a if result of confirm function is false
$(document).ready(function () {
$(".deleteJob").on("click", function (e) {
if (!confirm("Are you Sure want to delete!")) {
e.preventDefault();
}
});
});
- [Django]-Django Allauth Ignoring Adapter
- [Django]-How to use Apache to serve Django server and React client?
- [Django]-How to import django models in scrapy pipelines.py file
- [Django]-Postgres 9.4 Django 1.9 get all json keys