0

I need help in jquery slider range for getting between values like, i have defined array var valMap = [0, 25, 50, 100, 250, 500]; if user select 0 to 100 so i want to print or get the between numbers right now i can get only two values first value and end value, i have post my code kindly help me

$(function() {
    var valMap = [0, 25, 50, 100, 250, 500];
    $("#lens-range").slider({
        min: 0,
        max: valMap.length - 1,
        values: [0, 1],
        slide: function(event, ui) {
            $("#lensrange").val('Miles: ' + valMap[ui.values[0]] + ' - ' + valMap[ui.values[1]]);
            console.log($.inArray(ui.value, valMap) != -1);
        },
        stop: function(event, ui) {
            for (var i = 0; i < valMap.length; i++) {
                console.log(valMap[ui.values[i]]);

            }
        }
    });
    $("#lensrange").val('Miles: ' + valMap[$("#lens-range").slider("values", 0)] + ' - ' + valMap[$("#lens-range").slider("values", 1)]);
});
Sushil
  • 2,837
  • 4
  • 21
  • 29
Danish
  • 11
  • 2

1 Answers1

0

You could use slice(). See http://www.w3schools.com/jsref/jsref_slice_array.asp

Like this:

var rangeArray = valMap.slice(ui.value[0], ui.value[1])

EDIT:

Slice returns from start index until, not including, end index. To include end index simply call it like this:

var rangeArray = valMap.slice(ui.value[0], ui.value[1]+1)
Julien Grégoire
  • 16,864
  • 4
  • 32
  • 57
  • Really appreciate Mr. Julien for help, you have resolved my issue but the new issue is I have five indexing [0, 25, 50, 100, 250, 500]; in my array & slice is showing only four indexing when i move slider start point zero and end point 500; The output is [0, 25, 50, 100, 250]. Please help also. – Danish Jun 23 '15 at 03:47
  • Thanks for resolve my issue, i have one more problem can you tell me how can i assign php array values which is from database i want to get array values from the database and assigned those values into this var valMap = [0, 25, 50, 100, 250, 500]; – Danish Jun 23 '15 at 20:43
  • Well this is a whole other topic. What do you have already? Have a look here for a start: http://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to-javascript – Julien Grégoire Jun 23 '15 at 22:32
  • Thanks julien, i stuck another issue basically i need associative array in jquery var valMap = ["0"=>"4370", "25"=>"4371", "50"=>"4372", "100"=>"4373", "250"=>"4374", "500"=>"4375"]; how can i get its values within var rangeArray = valMap.slice(ui.value[0], ui.value[1]) – Danish Jun 24 '15 at 07:59