Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update html5 range on change of a text input?

I have a html5 range input and a text box input. When the range changes, the text box will get updated. But what should I do so that when I put a number in the text box, the range input gets updated?

This is my current code:

<div>
<input id="slider" type="range" min="0" max="200" />
<input id="box" type="text" value="0"/>
</div>

<script>
var slider = document.getElementById('slider');
$('#box').change(function(){slider.value=parseInt(this.value)});
</script>

When I edit my text box, my slider (range input) does NOT change. What am I doing wrong? Can it be that I shouldn't be using slider.value to update the slider? If that is the reason, what is the correct way to do that?

like image 800
Zening Qu Avatar asked Nov 20 '12 14:11

Zening Qu


People also ask

How do you change the input range?

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!

What parameters does range input accept in html5?

min (The lowest accepted value in the range) max (The highest accepted value in the range) step (The increment/decrement step value default is 1) value (The starting or default value of the slider)

How do you limit input numbers in html?

The HTML <input> tag is used to get user input in HTML. To give a limit to the input field, use the min and max attributes, which is to specify a maximum and minimum value for an input field respectively. To limit the number of characters, use the maxlength attribute.


1 Answers

Hey Everyone Those who don't know , we don't need any js or jquery for this

<form>
  <div>
    <input id="rangeInput" type="range" min="0" max="200" oninput="amount.value=rangeInput.value" />
    <input id="amount" type="number" value="100" min="0" max="200" oninput="rangeInput.value=amount.value" />
  </div>
</form>
like image 79
Suraj Rawat Avatar answered Oct 19 '22 04:10

Suraj Rawat