Home > Mobile >  How to delete an object with a windows.confirm?
How to delete an object with a windows.confirm?

Time:05-31

I have a template that lists all the activities of a client. In this template, I have a button to delete any activity I choose. This button has a confirmation to delete through a windows.confirm. But it's not working the way you expect. Sometimes the button works, sometimes it doesn't.

{% for servico in object_list %}                   
     {{ servico.refferring_funcionario }}
     {{ servico.get_lista_servico_display }}
     {{ servico.data_servico }}
     R$ {{ servico.valor_servico }}
     <a href="{% url 'servico:editar-servico' servico.id %}" >Edit</a>
     <a href=""  onclick="return myFunction()">Delete</a>
{% endfor %}

Js

<script>
   function myFunction() {
        if (window.confirm("Você tem certeza que deseja excluir ?")) {                                      
            window.location.href="{% url 'servico:excluir-servico' servico.id %}";
        }
   }

CodePudding user response:

I don't think this is the problem, but to start solving the problem I would set the value of href to #

<a href="#"  onclick="return myFunction()">Delete</a>
  • Related