Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson 13 #140

Open
Georgeikani opened this issue Aug 13, 2024 · 5 comments
Open

Lesson 13 #140

Georgeikani opened this issue Aug 13, 2024 · 5 comments

Comments

@Georgeikani
Copy link

How do i generate the Id in product.js.
Const product = [{
id:
name:
}]

@okontg
Copy link

okontg commented Aug 17, 2024

use the valuable name of the dataset (productId) in the querySelector, example below.

//product quantity
const quantitySelector = document.querySelector(.js-quantity-selector-${productId}).value;
const covertToNumber = Number(quantitySelector);

@Frimpong-123
Copy link

use the valuable name of the dataset (productId) in the querySelector, example below.

//product quantity const quantitySelector = document.querySelector(.js-quantity-selector-${productId}).value; const covertToNumber = Number(quantitySelector);

please are you sure this code works cos i have tried that so many times and i am still not getting the results

@okontg
Copy link

okontg commented Sep 4, 2024

this is the HTML

and this the JavaScript
const cartInputQuantity = document.querySelector(.js-cart-quantity-input-${productId}).value;
let newQuantity = Number(cartInputQuantity);

actually, i don't know how you sent your code.

here is the complete code, starting from the 'save link'.
the save link, i use selectAll, in the 'save link' gave it a data-set (e.g, data-product-id=${matchingProduct.id}).
use the variable name you use for the dataset ( e.g, const productId = saveCartQuantity.dataset.productId;), use the variable name in your input (e.g, const cartInputQuantity = document.querySelector(.js-cart-quantity-input-${productId}).value;)

//--------------------------Javascript
document.querySelectorAll('.js-save-cart-quantity')
.forEach((saveCartQuantity)=>{
saveCartQuantity.addEventListener('click',()=>{
const productId = saveCartQuantity.dataset.productId;

    const cartInputQuantity = document.querySelector(`.js-cart-quantity-input-${productId}`).value;
    let newQuantity = Number(cartInputQuantity);
  });
});

@Georgeikani
Copy link
Author

Hi Okontg thanks for helping out, but it was resolve. is there any means i can reach you either mail or whatsapp i'd really appreciate it

@Georgeikani
Copy link
Author

id: "e43638ce-6aa0-4b85-b27f-e1d07eb678c6", },

is how to generate the id i meant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants