Search code examples
javascriptjqueryjquery-uiif-statementuislider

how to use if Statements with jQuery ui Slide Ranger?


I have a jQuery ui Slide ranger. What I want to do is to be able to do something if the range is between a specific amount. So for example, to display something when the range slider is between 300900 & 666700. I'm having troubles into putting it in a variable in terms of min/max values and how I would get the two values from the range slider into the if statement. Heres the code:

$(function() {
  $( "#slider-range" ).slider({
    range: true,
    min: 249500,
    max: 750000,
    values: [ 75, 300 ],
    slide: function( event, ui ) {
      $( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
    }
  });
  $( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) +
    " - $" + $( "#slider-range" ).slider( "values", 1 ) );
});

Thank you.

Another example would be to display something if the user had the min value of 300900 and the max value on 600700.


Solution

  • You can check those values in the slide function:

    slide: function( event, ui ) {
        if(ui.values[0] ==  300900  && ui.values[1] == 600700  ){
            doSomething();
        }
    }