I'm having a small issue here getting my slider to update the value of itself being displayed on screen. For some reason I can't get to to function correctly. If someone with a little more experience here could help that would be fantastic. I've added the full page of my code, I have four sliders on the page but I'm only trying to achieve this with the first one for the time being.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.slidecontainer {
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
background: #4CAF50;
appearance: none;
width: 25px;
height: 25px;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
background: #4CAF50;
cursor: pointer;
}
</style>
</head>
<script>
document.getElementById("P1H").slider.onchange(function(){updateSlider()}
function updateSlider(){ document.getElementById('P1H_value').innerHTML = document.getElementById("P1H").value }
</script>
<body>
<h1>Player 1</h1>
<div class="slidecontainer">
<h2 align="center">Health:</h2>
<h3 align="center" id="P1H_value">0</h3>
<input type="range" min="1" max="100" value="100" class="slider" id="P1H" >
<h2 align="center">Shield:</h2>
<h3 align="center" id="P1S_value">0</h3>
<input type="range" min="0" max="100" value="0" class="slider" id="P1S">
</div>
<h1>Player 2</h1>
<div class="slidecontainer">
<p align="center">Health:</p>
<p align="center" id="P2H_value">0</p>
<input type="range" min="1" max="100" value="100" class="slider" id="P2H">
<p align="center">Shield:</p>
<p align="center" id="P2S_value">0</p>
<input type="range" min="0" max="100" value="0" class="slider" id="P2S">
</div>
<h1>Player 3</h1>
<div class="slidecontainer">
<p align="center">Health:</p>
<p align="center" id="P3H_value">0</p>
<input type="range" min="1" max="100" value="100" class="slider" id="P3H">
<p align="center">Shield:</p>
<p align="center" id="P3S_value">0</p>
<input type="range" min="0" max="100" value="0" class="slider" id="P3S">
</div>
<h1>Player 4</h1>
<div class="slidecontainer">
<p align="center">Health:</p>
<p align="center" id="P4H_value">0</p>
<input type="range" min="1" max="100" value="100" class="slider" id="P4H">
<p align="center">Shield:</p>
<p align="center" id="P4H_value">0</p>
<input type="range" min="0" max="100" value="0" class="slider" id="P4S">
</div>
</body>
</html>