jquery-ui slider update value from code
Asked Answered
H

3

5

i've got a problem with updating slider value from code. i have tried

$('#slider').slider('value', newValue);
$('#slider').val(newValue).slider();
$('#slider').val(newValue).slider('refresh');

and no result

any other suggestions

Hebner answered 25/5, 2011 at 23:6 Comment(0)
E
9

here is a sample code

Determines the value of the slider, if there's only one handle. If there is more than one handle, determines the value of the first handle.

Code examples

Initialize a slider with the value option specified.
$( ".selector" ).slider({ value: 37 });
Get or set the value option, after init.
//getter
var value = $( ".selector" ).slider( "option", "value" );
//setter
$( ".selector" ).slider( "option", "value", 37 );
Enterpriser answered 25/5, 2011 at 23:9 Comment(2)
Turned out that I had invalid selector.Hebner
@maxlego: Try this $( "#slider" ).slider({ value: 37 }); to set slider value.Enterpriser
O
1
<html>
<input type="text" id="amount">
<input type="text" id="amount2">
<div id="slider-range"></div>
</html>

_

<script>
$(function() {
$( "#slider-range" ).slider({
    range: true,
    min: 0,
    max: 217,
    values: [ 0, 217 ],
    slide: function( event, ui ) {
        $( "#amount" ).val( ui.values[ 0 ] );
        $( "#amount2" ).val( ui.values[ 1 ] );
    }
});

$("#amount").change(function() {
    $("#slider-range").slider('values',0,$(this).val());
});
$("#amount2").change(function() {
    $("#slider-range").slider('values',1,$(this).val());
});

});
</script>

https://jsfiddle.net/brhuman/uvx6pdc1/

Olio answered 3/7, 2016 at 13:16 Comment(0)
C
-1

Just call showSlider() which was in slider.js file wherever u want. It will automatically refresh.

Columbary answered 31/10, 2014 at 14:37 Comment(1)
From the question there's no evidence that the user is using slider.jsHeathheathberry

© 2022 - 2024 — McMap. All rights reserved.