I have the following HTML:
var mySlider = document.getElementById("mySlider");
var stored = localStorage.getItem("myData");
if (stored == null)
mySlider.value = 5;
else
mySlider.value = stored;
mySlider.addEventListener("change", () => {
localStorage.setItem("myData", mySlider.value);
});
<form oninput="myNumber.value=mySlider.value">
<input type="range" id="mySlider" min="0" max="10" />
<output for="mySlider" id="myNumber">default</output>
</form>
All the getting and setting of the data to and from storage and the range slider seem to be working fine; the slider loads up to whatever previous value I had set it to. But the output myNumber only ever seems to respond to manual movements of the slider; it shows its original value "default" instead of the value of the input slider on initialization, up until I actually start moving the slider around.
I know I can go ahead and just set the value of the output when I set the value of the the slider, but it seems like that defeats the purpose of having the output element in the first place. Isn't the output supposed to show the results of the input whenever it's changed, regardless of whether that change comes from javascript or user interaction? How do I get it to behave this way?
oninputis only triggered by changing the input via mouse or keyboard.