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

178
Vistas
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 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