0

I'm trying to get the values of the current position of the range slider, so as to put in an object for my ajax request...

let minPrice;
let maxPrice;
$('.range-slider').on('start', function(input) {
   minPrice = input.from;
   maxPrice = input.to;         
});       
console.log(minPrice,maxPrice);                                 
Kanya
  • 26
  • 6
  • 1
    The simple answer is, you don't. The event listener in your code is an _asynchronous_ function. Try this: change your current `console.log` to `console.log('outside')` and add a `console.log('inside')` inside the callback function (either above or below the two assignments). Now load your page. You will see that the `outside` message is logged immediately. Then start dragging the slider and you will see the 'inside' message. – Michael Geary Jul 16 '20 at 21:51
  • 1
    To fix this, whatever action you need to take when the user starts dragging the slider, you need to put that _inside_ the callback, or in another function that you _call from_ the callback. – Michael Geary Jul 16 '20 at 21:52
  • 1
    And here is some reading on the topic: https://www.google.com/search?q=javascript+asynchronous+callback – Michael Geary Jul 16 '20 at 21:53

0 Answers0