kayhan
kayhan

Reputation: 45

input type range show range value in input type number in html

How do I change the following code so that I can use it for multiple inputs of number type?

function updateTextInput(val) {
          document.getElementById('textInput').value=val; 
        }
<input type="range" name="rangeInput" min="0" max="100" onchange="updateTextInput(this.value);">
<input type="text" id="textInput" value="">

Upvotes: 0

Views: 2550

Answers (1)

Ilya Sheershoff
Ilya Sheershoff

Reputation: 479

So. What I'd do - I'd expand the function so it would work with several IDs. Something like that:

function updateTextInput(val, elId) {
          document.getElementById(elId).value=val; 
        }
<input type="range" name="rangeInput1" min="0" max="100" onchange="updateTextInput(this.value, 'textInput1');">
<input type="text" id="textInput1" value="">
<br/>
<input type="range" name="rangeInput2" min="0" max="100" onchange="updateTextInput(this.value, 'textInput2');">
<input type="text" id="textInput2" value="">

Upvotes: 2

Related Questions