Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

241
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda