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

93
Visualizações
How to change each element of django template for loop with javascript
        {% for transaction in transactions %}
            <ul>
                <li>{{transaction.number}}</li>
                <li id = "price">{{transaction.price}} USD </li>
                <li>{{transaction.created}}</li>
            </ul>
            <hr>
        {% endfor %}

I made currency converter option with api. In this case user has 3 transactions. How can i change each transaction's currency with javascript after using dropdown menu? When i change currency by document.getElementById("price").innerHTML = ${totalExchangeRate2} ${selectValue}; (it is onchange with dropdown menu) only first price changes. How to make this django loop avaible in javascript or something like this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

instead of your li:

<li id = "price">{{transaction.price}} USD </li> 

create it with unique id

<li id = f"price-{{transaction.pk}}">{{transaction.price}} USD </li>

from this moment each li element will have its own unique id, with which you could change it with JS

next with JS you can do something like this:

document.getElementById("price-1").innerHTML = ${totalExchangeRate1} ${selectValue}
document.getElementById("price-2").innerHTML = ${totalExchangeRate2} ${selectValue}
document.getElementById("price-3").innerHTML = ${totalExchangeRate3} ${selectValue}

it would be better done with ForEach, but this is only example

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