Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get values from JQuery - IonRangeSlider?

how can I get low and high values from ion.rangeSlider component by clicking a button?

This is my jQuery code:

<script>
    $(document).ready(function(){
        $("#range_1").ionRangeSlider({
            min: 10,
            max: 50,
            from: 10,
            to: 20,
            type: 'double',
            step: 1,
            prettify: true,
            hasGrid: false
        });
    });
</script>

<script>
 $(document).ready(function(){
    $('#get_values').click(function(){
            var low = $('#range_1').... ???;
            var high = $('#range_1').... ???;
            alert(low);
        });
 });
</script>
like image 799
Gem Avatar asked Oct 29 '14 21:10

Gem


5 Answers

// Launch plugin
$("#range").ionRangeSlider({
    type: "double",
    min: 0,
    max: 1000,
    from: 200,
    to: 500
});

// Saving it's instance to var
var slider = $("#range").data("ionRangeSlider");

// Get values
var from = slider.result.from;
var to = slider.result.to;

See solution at http://jsfiddle.net/2qLum6s7/. Works with latest version of Ion.RangeSlider (2.1.2).

like image 126
scahill Avatar answered Oct 20 '22 03:10

scahill


Use jQuery's data() method:

var low = $('#range_1').data().from;
var high = $('#range_1').data().to;
like image 34
soheilpro Avatar answered Oct 20 '22 04:10

soheilpro


Previous answer was based on old plugin API and don't work any more. Here is the new one, for 2.x version: http://jsfiddle.net/IonDen/2L15xoym/

var $range = $(".js-range-slider"),
    $result = $(".js-result"),
    $getvalues = $(".js-get-values"),

    from = 0,
    to = 0;

var saveResult = function (data) {
    from = data.from;
    to = data.to;
};

var writeResult = function () {
    var result = "from: " + from + ", to: " + to;
    $result.html(result);
};

$range.ionRangeSlider({
    type: "double",
    min: 10,
    max: 50,
    from: from,
    to: to,
    onStart: function (data) {
        saveResult(data);
        writeResult();
    },
    onChange: saveResult,
    onFinish: saveResult
});

$getvalues.on("click", writeResult);
like image 43
IonDen Avatar answered Oct 20 '22 04:10

IonDen


const range = $('#range_1');

const rangeData = range.data('ionRangeSlider');
const start = rangeData.result.from;
const max = rangeData.result.max;
// rangeData.result['property']

Version 2.3.0 (Tested)

like image 37
Andrii Kovalenko Avatar answered Oct 20 '22 04:10

Andrii Kovalenko


This method works on the latest version. Use event onChange to get data from attributes "from" and "to". Ion.RangeSlider v2.3.1:

    var slider = $('.js-range-slider');

    slider.ionRangeSlider({
        type: "double",
        prefix: '$',
        grid: true,
    });


    slider.on("change", function () {
        var $inp = $(this);
        var from = $inp.data("from");   // get data from attribute
        var to = $inp.data("to");       // get data from attribute

        console.log(from, to);          
});

Html Markup:

<input type="text" class="js-range-slider" name="my_range" value="" data-min="100" data-max="4000" data-from="1000" data-to="2000"/>
like image 45
Evgeny20 Avatar answered Oct 20 '22 05:10

Evgeny20