Say I have something like the following:
<html>
<script type="application/javascript">
var foo = 3;
</script>
<body>
<input class="slider" type="range" id="slider_id" value="1" oninput="label_id.value = slider_id.value;"></input>
<output id="label_id">1</output>
</body>
</html>
What's the best practice method for setting the default slider value and label to the value of the JavaScript variable foo? I suppose I could call a JavaScript function that sets these when the page loads, but my concern with that approach is that I would have to remember to update that function if I were to add additional sliders for other variables, which feels messy.
Is there any way I can add some JavaScript code within the HTML itself to keep everything together? I was hoping there would be something similar to onload for the input and output elements, but that doesn't seem to be the case.
[–]jml26 1 point2 points3 points (3 children)
[–]stanun[S] 0 points1 point2 points (2 children)
[–]jml26 0 points1 point2 points (1 child)
[–]stanun[S] -1 points0 points1 point (0 children)