Jim
Jim

Reputation: 743

update jquery ui range slider values

I want to update a jquery ui range slider with the values that are in two text boxes.

var minVal = $(this).find('.minTextBox').val();                  
var minVal2 = parseInt(minVal);
var maxVal = $(this).find('.maxTextBox').val();
var maxVal2 = parseInt(maxVal);
var myvalues = [minVal2, maxVal2];

var mySliderId = $(this).find('.RangeSlider').attr('id');

$( "#" + mySliderId).slider({
    range: true,
    values: myvalues,
    slide: function( event, ui ) {
        var idx = $(this).attr("id");
        x = idx.substr(idx.length-2);
        $( "#ctl00_ContentPlaceHolder1_Min"  + x ).val(ui.values[0]);
        $( "#ctl00_ContentPlaceHolder1_Max"  + x ).val(ui.values[1]);
    }
});

I'm trying to pass the myvalues array to the slider to overwrite the old values.

No matter what I try, I can't get this to work. I've looked at various other questions on SO and through the documentation but I can't get any closer.

Am I on the right lines with this?

Any help would be appreciated.

Upvotes: 1

Views: 1093

Answers (1)

Foreever
Foreever

Reputation: 7468

You don't need to initialize again. execute the below line to modify the range values.

$( "#" + mySliderId).slider( "option", "values", myvalues );

Upvotes: 1

Related Questions