Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

97
Views
Javascript: ¿La función de agregar al carrito de comercio electrónico no funciona en Javascript?

Estoy tratando de escribir una funcionalidad de agregar al carrito usando Javascript y django (la funcionalidad principal es Javascript).

He escrito este código para cart.js

 var updateBtns = document.getElementsByClassName('update-cart') console.log("Working"); for (i = 0; i < updateBtns.length; i++) { updateBtns[i].addEventListener('click', function(){ var productId = this.dataset.product var action = this.dataset.action console.log('productId is:', productId, 'Action is:', action) console.log('USER:', user) }) }

Y este es el código para la plantilla index.html

 {% for product in products %} {{ product.title }} {{ product.price}} <button data-product="{{product.id}}" data-action="add" class="btn btn-outline-secondary add-btn update-cart">Add to Cart</button> {% endfor %}

Cuando print(product.id) obtiene la identificación del producto específico, pero el botón no funciona. ¿Cuál podría ser el problema con mi código?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

¿Realmente llamaste a esa acción?

 for (i = 0; i < updateBtns.length; i++) { updateBtns[i].addEventListener('click', function(){ var productId = this.dataset.product var action = this.dataset.action // I think that you need to call the action window[action](productId); console.log('productId is:', productId, 'Action is:', action) console.log('USER:', user) }) }
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!