Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Console shows only old value (js, html)

so I’ve added slider that has range 0-4 and it shows value next to it but when I console log it shows only default value.

const output = document.getElementById("output").value;
let smth = document.getElementById("smth1");
let tb = document.getElementById("Test-button");

tb.addEventListener("click", () => {
  console.log(JSON.parse(JSON.stringify(output)))
});
</span><input type="range" value="0" min="0" max="4" oninput="this.nextElementSibling.value = this.value"><output id="output">0</output><br>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Because the output is set on load, not on click.
Do like this instead.

let smth = document.getElementById("smth1");
let tb = document.getElementById("Test-button");

tb.addEventListener("click", ()=>{
  const output = document.getElementById("output").value;
  console.log(JSON.parse(JSON.stringify(output)))
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading