1

Hello I have some input of type range on my code written with HTML like this :

this is my input :

  <input type="range" min="1" max="100" value="50" class="slider" id="myRange">

But I can't see the current value... How can I do to display it ?

Thank you very much.

3 Answers3

1

Use the value property of the input element:

function getValue() {

  let value = document.querySelector('#myRange').value

  // here we are logging the value in the console
  console.log(value)

}
<button onclick="getValue()">See value</button>

<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
Ivan
  • 34,531
  • 8
  • 55
  • 100
1

Here is the code, use value property of you range input to get the current value:

var res =  document.getElementById('currentValue');
    var rangeInput = document.getElementById('myRange');
    res.innerHTML = rangeInput.value;
    
rangeInput.addEventListener('change', function(e) {
    res.innerHTML = e.target.value
})
 <input type="range" min="1" max="100" value="50" class="slider" id="myRange">
<div id="currentValue"></div>
Ihor Lavs
  • 2,315
  • 2
  • 15
  • 26
  • Thx you but where do I put this `var res = document.getElementById('currentValue'); var rangeInput = document.getElementById('myRange'); res.innerHTML = rangeInput.value; rangeInput.addEventListener('change', function(e) { res.innerHTML = e.target.value })` – Peter Harris May 24 '18 at 12:26
  • You can put it in your javascript file. Do you have one? – Ihor Lavs May 24 '18 at 12:27
0

Try this:

function updateValue(val) {
          document.getElementById('textInput').value=val; 
 
        }
<input type="range" min="1" max="100" value="50" class="slider" id="myRange" onchange="updateValue(this.value);">
<input type="text" id="textInput" value="">
Suraj Libi
  • 515
  • 2
  • 9