-1

am working on a two paged rating site where am to get information from the main page and use it on the second page and am trying to assign the text content of a clicked div in the main page to rateNumber but for some reason it still gives me the initial empty string assigned to it when I try using it in the second page. pls can anyone help me out here.

here's the js code

const rates = document.querySelectorAll('.rates')
const submit = document.querySelector('.submit')
let rated = document.querySelector('.rated')
let rateNumber = ''

function toggle(){
  rates.forEach((rate) =>
    rate.classList.remove('active'))
  this.classList.add('active')
  rateNumber = this.innerText
  }
function setRate(){
  rated.innerText = rateNumber
}

for (let i = 0; i < rates.length; i++) {
  rates[i].addEventListener('click', toggle)
}

this is where am trying to assign it but it's not working and to b honest av ran out of ideas

  rates.forEach((rate) =>
    rate.classList.remove('active'))
  this.classList.add('active')
  rateNum = this.innerText
  }```
  • 2
    Each page is its own context. If you need data to be available across multiple pages from the same site (technically, from the same _origin_), use `localStorage`. And if you need two or more open tabs with pages from the same site to talk to each other, use `postMessage`, but that doesn't sound necessary here. – Mike 'Pomax' Kamermans Aug 18 '23 at 07:12
  • Yeah, If u need to use value in next page, It is better to use localStorage. It is very easy solution to issue you are encountering. – MenTalist Aug 18 '23 at 07:14
  • Please visit the [help], take the [tour] to see what and [ask]. Do some research - [search SO for answers](https://www.google.com/search?q=pass+javascript+to+next+page+site:stackoverflow.com). If you get stuck, post a [mcve] of your attempt, noting input and expected output using the [\[<>\]](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) snippet editor. – mplungjan Aug 18 '23 at 07:21

0 Answers0