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

3 Answers 3

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 );
Sign up to request clarification or add additional context in comments.

2 Comments

Turned out that I had invalid selector.
@maxlego: Try this $( "#slider" ).slider({ value: 37 }); to set slider value.
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/

Comments

-1

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

1 Comment

From the question there's no evidence that the user is using slider.js

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.