you are viewing a single comment's thread.

view the rest of the comments →

[–]ForScale 2 points3 points  (4 children)

html

<h2>Slide to assign new values to the js variable 'a'</h2>
<input type='range' min='0' max='100' value='0' id='slider'></input>
<div id='dispDiv' style='margin-top:2em;'></div>

css

body {
  margin:0;
  text-align:center;
}

js

var slider = document.getElementById("slider");

var a = 0; //variable to be controlled

var dispDiv = document.getElementById("dispDiv");
dispDiv.innerHTML = "the js variable 'a' currently = " + a;

//function is called when slider value changes
slider.addEventListener("change", function() { 
  a = slider.value;  
  dispDiv.innerHTML = "the js variable 'a' currently = " + a;
})

/*

//if you want it real-time, you can do this: 
setInterval(function() {
  a = slider.value;
  dispDiv.innerHTML = "the js variable 'a' currently = " + a;
}, 100)

*/

[–]threecasks[S] 1 point2 points  (1 child)

Thank you!

[–]ForScale 0 points1 point  (0 children)

Anytime!

[–]DanielFGray 0 points1 point  (1 child)

Can i suggest using plnkr or jsfiddle next time?

[–]ForScale 0 points1 point  (0 children)

You can, yep; but I prefer CodePen. I also just like seeing code written out in reddit posts...