Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
How to pass an object's id to a js function outside of a for ? DJANGO

I have a delete button that deletes an object from the database. This button has a js windows.confirm function for deletion. I need to pass servico.id to function so I can reference the object in the view. How do I do this?

<a href="#" class="btn btn-danger btn-sm" onclick="return myFunction()">Delete</a>

Script

        <script>
          function myFunction() {
            if (window.confirm("Você tem certeza que deseja excluir ?")) {
              window.location.href="{% url 'servico:excluir-servico' servico.id  %}";            
            }
          }
        </script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

html

   <a href="#" data-id="{{servico.id}}" id="de" class="btn btn-danger btn-sm" onclick="return myFunction()">Delete</a>

js

<script>
    function myFunction() {
     if (window.confirm("Você tem certeza que deseja excluir ?")) {
      _id = $('#').attr(''data-id)
      window.location.href="`${window.location.pathname}/${_id}`;";            
    }
   }
</script>

I used jquery you need to include it.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!