0

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="">

1 Answer 1

2

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="">

Sign up to request clarification or add additional context in comments.

1 Comment

Replacing "onchange" event by "onmousemove" event allow to see the selected value in real time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.