2

I am using this http://www.eyecon.ro/bootstrap-slider/ for a slider in a page I am working on,I don't understand the api. Can someone help me with this ?

$(..).slider('getValue')

returns the dom element while I saw this in the code

$(..).slider().getValue() 

which returns a method not found error. I am aware of the .slide event which can be used for this,but how do you access the value directly ?

Diadara
  • 591
  • 1
  • 3
  • 20

4 Answers4

12

I'am using it this way

<input type="text" id="slider1" class="span2 slider" value="80" data-slider-min="50" data-slider-max="90" data-slider-step="0.1" data-slider-value="83"  data-slider-selection="after" data-slider-tooltip="hide">
 $('.slider').on('slide', function (ev) {
        console.log($('#slider1').val());


    });

So I access value with $('#slider1').val(). I hope this is going to be helpful

DejanG
  • 525
  • 1
  • 10
  • 17
  • 1
    Yes, it works! The value of $(selector).slider('getValue') seems to be meaningless, but I don't know why. Thanks! – wagyaoo Jun 17 '14 at 04:45
  • not that .val() will return "" if the slider wasn't moved – ılǝ Dec 18 '14 at 13:35
  • @ılǝ because of that you initialize value to some number like i did value="80" – DejanG Dec 19 '14 at 08:39
  • Thank you so much @DejanG I've been trying to fix this problem for a while! – Ivan Dec 03 '16 at 18:48
  • From what I've seen $(selector).slider('getValue') will return an array for a range, while $(selector).val() will return a string. – Raf Oct 11 '21 at 11:47
3

The slider is technically a text input field.

So you can simply use $("#inputFieldID").val()

This will not provide any value until the slider is moved. So specify the initial value using the value attribute of the input tag.

Narendran Parivallal
  • 1,070
  • 1
  • 14
  • 16
  • This works great, just important to remember to provide a different id to the slider, eg data-slider-id="something-else", and access the original input field and not the slider id ($("#slider-id").val() always return empty string). – Ronen Ness Mar 28 '16 at 13:19
0

you can use this from the built in function

$("#rating").slider({
    change: function( event, ui ) {
        userRating = ui.value;
        // this will give you the real value of the slider after the change.
        alert(userRating); 
    }
});

and thank you i thought i coud share this with you guys :D

Alaa M. Jaddou
  • 1,180
  • 1
  • 11
  • 30
0
$('#idSlider').data('slider').getValue();
Igor Krupitsky
  • 787
  • 6
  • 9