Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

122
Visualizações
how to reuse a variable with everything and its value in another page of my project

im working on a e-commerce and im trying to do the page where you fill your info, but i cant use my variable cart, or my total.textContent i just need to show my cart, the total of the cart and my form but i cant use any of my variables or functions

enter code here

    const container = document.getElementById("container");
    
    const cartContainer = document.getElementById("cart-items");
    
    let cart = [];
    
    export let stock = [
    
        {id: 1, item: "Playera blanca - Logo rojo", precio: 265, imagen: '<img class="cart-review-img" src="./images/Playera blanca - Logo rojo.png" alt="">'
}];
    
    const upDateCart = () => {
        cartContainer.innerHTML = ""
    
        cart.forEach((prod) => {
            const div = document.createElement("div")
            div.className = ("cart-review-cotainer")
            div.innerHTML = `
            <div class="cart-image col-md-5">
                ${prod.imagen}
            </div>
            <div class="col-md-5 d-flex flex-column  justify-content-between">
                <div>
                    <p id="cart-item-name">${prod.item}</p>
                    <p id="cart-item-price">${prod.precio}</p>
                </div>
            </div>
            <div class="col-md-2 delete-container">
                <button onclick="deleteItem(${prod.id})" id="delete-item"><img class="delete-img" src="./images/trash-solid.svg" alt=""></button>
            </div>
            `
            cartContainer.appendChild(div)
    
           localStorage.setItem("newCart", JSON.stringify(cart))
           
        })
        total.innerText = cart.reduce((acc, prod) => acc + prod.precio, 0)
    }
    
    if(localStorage.getItem("newCart")) {
        newCart = JSON.parse(localStorage.getItem("newCart"))
        console.log(newCart)
        upDateCart()
    }
    
    window.deleteItem = deleteItem;
    
    window.cart = cart;
    
    window.test = test;
    
    window.newCart = newCart;

my files in vs code

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I couldn't run your snippet, but I guess

   if(localStorage.getItem("newCart")) {
        newCart = JSON.parse(localStorage.getItem("newCart"))
        console.log(newCart)
        cart = newCart;        // 👈 add this line maybe?
        upDateCart()
    }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda