Skip to content
Advertisement

Set value of HTML element from javascript

I am using session variable to keep track of items in the cart. I generate a table using loop to display contents of the cart. The code for table is as follow:

JavaScript

I am having problem with + and - buttons within a tags. I want to increment or decrement value in input field named quantity. But since i am generating table in a loop i do not know the id of each field. I want to do something like this:

JavaScript

But this method always increments first quantity field in the table. How do i get ids of other quantity fields in the table?

Advertisement

Answer

Dont use ids inside loop.Just use class for that>check the snippet for a smaple demo

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement