vendredi 2 novembre 2018

Passing value from HTML to JS

I am trying to create shopping cart which should work as it works in most of shops - if you click plus button you add extra copy of product to your shopping cart, if you click minus you remove one copy. I think everyone undersand what i mean. My buttons in HTML (it's hbs because i write in express.js) looks like this:

 <span class="minus bg-dark">-</span>
 <input type="number"  class="count" name="qty" value=>
 <span class="plus bg-dark">+</span> </span></div>

And i i have extra code in jQuery which change value of input when you click + or - and it works as it should. But i dont know how should i have variable this.qty.

I have tried with:

-onchange event, but its not working on values which are changed programmatically,

-finding this.item._id so i can redict my page to my /shopping-cart:id and it will add my items, but i cannot find this.item_id because it finds only first one.

Can someone help me? I am operating on database in node, passing variable to html than changing value on page in jQuery.




Aucun commentaire:

Enregistrer un commentaire