Skip to content
Advertisement

Update Input field value with value from a range slider using javascript

I’m trying to modify a how-to example which I got from W3Schools

The example is a range slider which display the value of the slider inside a <span> tag

What I would like to do is display the value inside an input field

JavaScript

Source: W3Schools range slider example

I would like to display the value inside an input field instead of the <span> tag so I have tried to modify the example:

JavaScript

but this doesn’t work as it only display the initial value and does not update if I move the slider knob

Advertisement

Answer

You can store the element’s reference in the output var & instead of innerHTML you could just use the value attribute.

Here’s the updated code for your reference:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement