Good evening!!
I'm using HTML input type range to create a slidebar. I would like to dynamically change the attribute "value" (default position of the cursor) before displaying the slidebar.
I can retrieve the value I need (from localStorage) but I don't manage to set it!!
Here is the range object:
<input type="range" min="0" max="1050" value="0" step="30" onchange="showValue(this.value); changeScrollBar(this.value);"/>
Now it is set to 0 but I would like to use a variable to change it (i.e I'll set a new variable foo=localStorage.getItem("foo2") then I would like to use value=foo in range)!
Any clue?
Thanks a lot!!!
The <input type="range"> defines a control for entering a number whose exact value is not important (like a slider control). Default range is 0 to 100. However, you can set restrictions on what numbers are accepted with the attributes below. Tip: Always add the <label> tag for best accessibility practices!
The "range" tag (actually a slider) in HTML 5 adds a ver useful HTML form control. In the IE browser, the slider value is displayed when you move the slider.
You get the DOM element for the <input>
tag and then use:
elem.value = foo;
If you add an ID to the input tag like this:
<input id="mySlider" type="range" min="0" max="1050" value="0" step="30" onchange="showValue(this.value); changeScrollBar(this.value);"/>
Then, you can do the whole thing like this:
var input = document.getElementById("mySlider");
input.value = localStorage.getItem("foo2");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With