Beginner
Beginner

Reputation: 191

How to get the value of Jquery UI slider? With 2 or more slider

Currently, I am using Jquery UI slider to get a rating scale of user. There exist not only a slider but more than 2. How do I get the value of each according each name? I had to accumulate them the total value according the different name.
Jquery UI slider Please click for snippet

Jquery UI slider

Upvotes: 0

Views: 36

Answers (1)

Neil
Neil

Reputation: 14313

I decided to write up some code to build an associated array that maps the name of the slider to the value.

r = {}
$( ".slider" ).each(function () {
  r[$(this).attr("name")] = $(this).slider("option", "value");
});
console.log(r);

Here's an example on how to use it:

$( ".slider" ).slider({
    value: 0,
    min: 0,
    max: 10,
    step: 1
}).on("slidestop", function () {
  r = {}
  $( ".slider" ).each(function () {
  r[$(this).attr("name")] = $(this).slider("option", "value");
});
console.log(r);
});

Upvotes: 2

Related Questions