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

Use data from variable in another function

I’ve got a function like this (value is from select):

function getSelectValuePower () {
 var power = document.getElementById("power").value;
  sessionStorage.setItem("power", power);
  console.log(power);
}

How can I use value from variable power in another function ?
For example :

I want to use it here :

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

function getValue () {
  var number = 10;
  var selectedValue = number + power;
  console.log(selectedValue2);
}

So, when my power is 7, the result in getValue() should be 17.

I tried to do it with global variables, but doesn’t work.

>Solution :

Get power in second function:

var power = sessionStorage.getItem("power");
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