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

239
Views
How to extract the id of a Django formset in Javascript?

I have a doubt what happens is that I am trying to extract the id of a Django formset in Javascript, however when trying to do it I realized that this appears in Chrome DevTools:

S.fn.init

[[Prototype]]: Object (0)

That is, nothing is happening, but it seems strange to me because when printing in the console I get the id name that I want

what is happening and how can I extract its id and therefore the value??

calculate.js


//the number of total forms is taken

var formId="id_form-TOTAL_FORMS"
var form_idx = document.getElementById('id_form-TOTAL_FORMS').value;
console.log("el valor es:" + form_idx);
var totalForms=parseInt($('#'+formId).val());
console.log("totalForms:"+totalForms)
console.log(totalForms+1);

//dynamic id are created

var formset_quantity='id_form-'+form_idx+'-quantity';
var formset_unit_price='id_form-'+form_idx+'-unit_price';
console.log('formset quantity: '+formset_quantity);
console.log('formset unit price: '+formset_unit_price);


//the value of the one that contains the dynamic id is taken

//This is when everything goes wrong because when printing in the console I get the error above,
// as if that id does not exist(formset_quantity and formset_unit_price) or I am not creating it correctly

var id_formset_quantity=document.getElementById('formset_quantity').value;
var id_formset_unit_price=document.getElementById('formset_unit_price').value;
var formset_total_price=document.getElementById('id_form-'+form_idx+'-total_price');


presupuestos-forms.html


td id="parent_id_form-0-quantity">
  <input type="number" name="form-0-quantity" class="form-control" id="id_form-0-quantity">
</td>
<td id="parent_id_form-0-unit_price">
   <input type="number" name="form-0-unit_price" class="form-control" id="id_form-0-unit_price">
</td>
<td id="parent_id_form-0-total_price">
   <input type="number" name="form-0-total_price" class="form-control" id="id_form-0-total_price">
</td>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Leave out the quotation marks when you refer to a variable. Otherwise it will be interpreted as a string.

var id_formset_quantity=document.getElementById(formset_quantity).value;
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!