I have the code below in my website and integrated a range slider using HTML5. I want the slider to update the text-input with the value and vice versa. Would I do this using jQuery? If so can you give me example code?
Thanks.
<input type="text" name="chance" id="chance" class="text" value="50">
<input type="range" id="chance" class="vHorizon" min="0.01" max="98" style="background-color: #00aec8; width: 50%;">
You can use change
event on slider and keyup
event on textbox to update the values.
HTML
<input type="text" name="chance" id="chance" class="text" value="50">
<input type="range" id="chanceSlider" class="vHorizon" min="0.01" max="98" step="0.01" style="background-color: #00aec8; width: 50%;">
jQuery
$('#chanceSlider').on('change', function(){
$('#chance').val($('#chanceSlider').val());
});
$('#chance').on('keyup', function(){
$('#chanceSlider').val($('#chance').val());
});
And jsfiddle to play with
http://jsfiddle.net/tDkEW/1/
An improvement I found useful
$('#chanceSlider').on('input change', function(){
$('#chance').val($('#chanceSlider').val());
});
jsfiddle http://jsfiddle.net/tDkEW/408/
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