tags:

views:

164

answers:

3

How can I control 2 amounts with 1 slider ,

Below is the code I have for one slider controlling one amount.

$(function() {
 $("#slider").slider({
  value:38.11,
  min: 38.11,
  max: 100,
  step: 1,
  slide: function(event, ui) {
   $("#amount").val('$' + ui.value);
  }
 });
 $("#amount").val('$' + $("#slider").slider("value"));
});

Can any one help ?

A: 
$(function() {
        $("#slider").slider({
                value:38.11,
                min: 38.11,
                max: 100,
                step: 1,
                slide: function(event, ui) {
                        $("#amount").val('$' + ui.value);
                        $("#otherAmount").val('$' + ui.value);
                }
        });
        $("#amount").val('$' + $("#slider").slider("value"));
        $("#otherAmount").val('$' + $("#slider").slider("value"));
});
ammoQ
So how would I make the "otherAmount" take away 1 every time the slider moves and the "Amount" add 1 ? I actually got it working like your code above before but I could not find the way to make the step be a minus figure ? I am basically trying to make the Amount go up and the otherAmount go down
Oliver Bayes-Shelton
$("#otherAmount").val('$' + (100-ui.value));--------------------------------------------------------------------$("#otherAmount").val('$' + (100-$("#slider").slider("value"));
ammoQ
I didnt wory dude :(
Oliver Bayes-Shelton
A: 

I think instead of value you use values and give multiple values, so:

values: [1,5,9]

this should help explain http://docs.jquery.com/UI/Slider#option-values

Wayne Austin
Great , Thank you.
Oliver Bayes-Shelton
+1  A: 

Edit If you want to handle 2 values with the same slider, adding and subtracting so their total is always the same the solution is pretty easy. In the slide function you would do something like this:

$(function() {
    $("#slider").slider({
            value:38.11,
            min: 38.11,
            max: 100,
            step: 1,
            slide: function (event, ui) {
                $("#amount").val('$' + ui.value);
                $("#otheramount").val('$' + (100 - ui.value));
}
    });
    $("#amount").val('$' + $("#slider").slider("value"));
});

This is how the complete function would look like.

googletorp
I tried range and it basically gave me a double sided slider. I am looking to have 1 Slider but the slider controls 2 values. When the slight moves right it add to "Amount" and takes away from "otherAmount" how could I do this ?
Oliver Bayes-Shelton
I didnt have much look with it for some reason could you show me an example with the full code sorry dude :(
Oliver Bayes-Shelton
Thanks very very much just one comment whre it has (event ui) you made an error the fix is (event, ui) Also I have hit you up on twitter hope you dont mind
Oliver Bayes-Shelton
Right, I did a lot of c/p'ing so delete the "," by accident. Updated now.
googletorp