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

189
Views
How to pass Django formset form variable to JavaScript function

Basically I am using formsets, each form has a form ID and a deleted button amongst other things. When the delete button is clicked i'd like to call a function and pass the form ID to it, how can i achieve this?

{% for form in formset %}

{{ form.form_id_test }}

<button id="delete-form" type="button" class="btn btn-primary mb-2" 
onclick="deleteFormFunc({{ form.form_id_test }})">
    Delete Form
</button>

{% endfor %}

I am not able to pass the arguments like this, basically syntax error.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can obtain the form id of a formset form with form.id, eg,

{% for form in formset %}
    ...onclick="deleteFormFunc('{{ form.id }}')">...
{% endfor %}

...which should be a string value like 'id_form-1-id' that you can use in document.getElementById() in your deleteFormFunc

about 4 years ago · Juan Pablo Isaza Report

0

    ...onclick="deleteFormFunc(this.id)">...

this.id will get the id of the tag it is encoded in.

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!