Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

249
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda