windows 10 pro office 2019 pro office 365 pro windows 10 home windows 10 enterprise office 2019 home and business office 2016 pro windows 10 education visio 2019 microsoft project 2019 microsoft project 2016 visio professional 2016 windows server 2012 windows server 2016 windows server 2019 Betriebssysteme office software windows server https://softhier.com/ instagram takipçi instagram beğeni instagram görüntüleme instagram otomatik beğeni facebook beğeni facebook sayfa beğenisi facebook takipçi twitter takipçi twitter beğeni twitter retweet youtube izlenme youtube abone instagram

Need help displaying the value of a range slider

Asked By: Anonymous

Hello I am trying to display the output of a slider through JS. Upon running I am met with an error. ‘Cannot read property of null’.

HTML code:

<div class = 'sliderContainer'>
    <h1> Select Password Length</h1>
    <input type = 'range' min='8' max='16' value='10' id='myRange' class='slider'>
    <p>Password Length: <span id='length'></span></p>
</div>

JS code:

var slider = document.getElementById('myRange');
var output = document.getElementById('length');
output.innerHTML = slider.value;

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

Any help is appreciated! Thank you for your time.


Solution

Answered By: Anonymous

The document probably hadn’t loaded the input before you tried selecting it. Add an event listener for DOMContentLoaded:

_x000D_

_x000D_

document.addEventListener("DOMContentLoaded", function() {
  var slider = document.getElementById('myRange');
  var output = document.getElementById('length');
  output.innerHTML = slider.value;

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

_x000D_

<div class='sliderContainer'>
  <h1> Select Password Length</h1>
  <input type='range' min='8' max='16' value='10' id='myRange' class='slider'>
  <p>Password Length: <span id='length'></span></p>
</div>

_x000D_

_x000D_

x000D

techinplanet staff


Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno