-4

I'm trying to get the value from a range slider bar but getting this instead: [object HTMLInputElement].

This is the setup I have:

Any idea what I might be doing wrong?

var slider = document.getElementById("ran");
var output = document.getElementById("demo");
output.innerHTML = slider.value;

slider.oninput = function() {
  output.innerHTML = this.value;
}

var sliderbar = document.getElementById('ran');
sliderbar.onmouseup = function() {
  console.log(sliderbar); // alert shows [object HTMLInputElement]
}
<div class="slidecontainer">
  <span id="demo" style="font-weight: bold"></span><strong>miles</strong>
  <form>
    <input type='range' min='1' max="6" step="1" class="slider" id='ran' />
  </form>
</div>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Dev
  • 437
  • 6
  • 25
  • You seem to think the reference to a DOM element was the same as it’s value. – CBroe Jul 24 '18 at 09:25
  • 1
    `alert(sliderbar.value);` – JavaScript Jul 24 '18 at 09:25
  • Voting to close as _This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting._ – mplungjan Jul 24 '18 at 09:28
  • @mplungjan - Good point, did the same. Alternately, there *has* to be a "use `.value`" answer to a similar question, though I don't have an example handy. – T.J. Crowder Jul 24 '18 at 09:28
  • https://stackoverflow.com/questions/41216153/javascript-error-object-htmlinputelementobject-htmlinputelement – mplungjan Jul 24 '18 at 10:59
  • https://stackoverflow.com/questions/26205691/html-javascript-function-issue-object-htmlinputelement-error-output – mplungjan Jul 24 '18 at 10:59

1 Answers1

2

That's because sliderBar refers to the element. If you wants its value, use its value property, e.g.,sliderBar.value (or the slider-specific properties, if any, but I think slider just uses value).

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875