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

177
Visualizações
while working for dynamic content in django, javascript code written only works with first item of the loop

Here is the HTML template where javascript code is implemented inside the for loop. I am trying to take the required data from django models.

{% for other_campaign in other_campaigns %}
<div class="container" style="background-color:#f1f1f1">
  <div class="row">
    <div class="column-33">
      <img src="{% if other_campaign.Image %}
      {{other_campaign.Image.url}}
      {% else %}
      {% static './Images/blank.jpg' %}
      {% endif %}" class="camp_img" alt="App">
    </div>
    <div class="column-66">
      <a href="{% url 'detail' other_campaign.id %}" class="victim"><b>Victim: {{other_campaign.Name}}</b></a>
      <div class="target"><b><i>Target Amount:</i> {{other_campaign.Target}}</b></div>
      <div class="target"><b></b><i>Collected Amount:</i> {{other_campaign.Collected}}</div>
      <br>
      <p><b>Info: {{other_campaign.Info}}</b></p>
      <br>
      <div class="progress">
        <div class="progress-bar" role="progressbar" style="width: 25%;" aria-valuenow="25" aria-valuemin="0"
          aria-valuemax="100"></div>
        
        <br>
      </div>
      <div class="progress_text">Rs. {{ other_campaign.Collected }} - Done</div>
      <br>
      <br>
      <button class="button"><a href="#" class="donate_here">Donate Here</a></button>
      <br>
      <div style="float: right;">Date_added: {{other_campaign.Date_added}}</div>
    </div>
    <br>
  </div>
</div>

here is the javascript code

<!-- progress bar script -->
<script>
  const progress = document.querySelector(".progress-bar")
  const progpercent = {{other_campaign.Collected}}/{{other_campaign.Target}};
  progress.style.width = `${progpercent * 100}%`;
</script>
{% endfor %}

And here is the image of output in website.

about 4 years ago · Juan Pablo Isaza
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