How would I paste this Javascript into a new html page

This is for a add to cart function, I have it working but its on the same page as my items but i want the cart on a new page but cant get the products to add to cart on the new page

function addItemToCart(title, price, imageSrc) {
    var cartRow = document.createElement('div')
    var cartItems = document.getElementsByClassName('cart-items')[0]
    var cartItemNames = cartItems.getElementsByClassName('cart-item-title')

    var cartRowContents = `
        <div class="cart-item cart-column">
            <img class="cart-item-image" src="${imageSrc}" width="100" height="100">
            <span class="cart-item-title">${title}</span>
        <span class="cart-price cart-column">${price}</span>
        <div class="cart-quantity cart-column">
            <input class="cart-quantity-input" type="number" value="1">
            <button class="btn btn-danger" type="button">REMOVE</button>
    cartRow.innerHTML = cartRowContents
    cartRow.getElementsByClassName('btn-danger')[0].addEventListener('click', removeCartItem)
    cartRow.getElementsByClassName('cart-quantity-input')[0].addEventListener('change', quantityChanged)

Hi kylegilmartin5,

I’m not sure I understand the situation, maybe b/c I’m barely a noob in JavaScript. :slightly_smiling_face:

How are you storing/keeping track of the user’s cart?

Moved to JavaScript to give you a better chance of a good answer. :wink:

1 Like

Iam storing it locally in the html file

 <section class="container content-section">
    <h2 class="section-header" id="CartAnckor">CART</h2>
    <div class="cart-row">
      <span class="cart-item cart-header cart-column">ITEM</span>
      <span class="cart-price cart-header cart-column">PRICE</span>
      <span class="cart-quantity cart-header cart-column">QUANTITY</span>
    <div class="cart-items">
    <div class="cart-total">
      <strong class="cart-total-title">Total</strong>
      <span class="cart-total-price">$0</span>
    <button class="btn btn-primary btn-purchase" type="button">PURCHASE</button>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.