views:

1001

answers:

2

jQuery 1.3.2 / jQueryUI 1.7 / Slider

$("#slider").slider({
  range: "min",
  min: 0,
  max: 40,
  value: 0,
  slide: function(event, ui) {
   CalculateOrder(event, ui);
  }
 });

it starts off just fine, but after I move the slider I can't get it back to 0, ui.Value is 1 when i slide it all the way to the left.

I've tried setting

min:-1

this sets the ui.Value to -1 when i slide it to -1, but when I'm at 0 the ui.Value is still 1.

Any ideas?

+3  A: 

What you want is to get the value when the slider has stop, not during the slide. From my experience, the slide event will get you the previous position of the slider. Stop will give you the value of the slider where the user move it to.

 $("#slider").slider({
        range: 'min',
     min: 0,
     max: 40,
     value: 1,
     step: 10,
     slide : function(event, ui){
      console.log("previous value:"+ $(this).slider('option', 'value'));
     },
     stop: function(event, ui){
      console.log("Current value:"+ $(this).slider('option', 'value'));
     }
   });
Scott
thanx, stop: did it !!!
roman m
Actually, there's a subtle difference in all this (I just ran into this myself). You should use "ui.value" to get the value in your slide event handler. That will give you the *current* value. You will get the previous value if you fetch it by asking the slider for its handle value (e.g. .slider('value') or .slider('option', 'value'), etc.).This matters if you are trying to say dynamically update a label while the user is sliding the handle around. Summarizing: if you use ui.value to get the value in the slide event handler, you won't need to use a stop event handler.
chrisrbailey
Chris's comment was right on the money. If you use ui.value within your "slide" handler, you can get the current value of the slider, as opposed to the previous value.
Shane Larson
A: 

thats right! its working!!! many thanks:)

Please don't use an answer to respond to another answer. That's what comments are for.
Paul Tomblin
i don't think you can comment with 0 rep. just delete this answer
roman m