1

I need help with two jquery form sliders. I have this code

$("#slider").slider({
range: "min",
value: 10,
step: 10000,
min: 100000,
max: 1000000,
});

$('#slider').slider()
.on('slide', function(ev){
var datafirst = ev.value*(Math.pow(1.11, 5));
document.getElementById("bar").innerHTML = datafirst;

});

$("#slider-year").slider({
range: "min",
value: 10,
step: 1,
min: 5,
max: 15,
});
$('#slider-year').slider()
  .on('slide', function(ev){
var datasecond = ev.value;
document.getElementById("yeartotal").innerHTML = datasecond;

  });

and what I need is to take variable from first slider and second slider and count them that is all.

Thank you for every answer.

folpy
  • 139
  • 2
  • 10

1 Answers1

0

LIVE DEMO

var datafirst = 0;
var datasecond = 0;

$("#slider").slider({
  range: "min",
  value: 10,
  step: 10000,
  min: 100000,
  max: 1000000,
  slide: function( ev, ui ) {
    datafirst = ui.value * Math.pow(1.11, 5);
    $("#bar").text( datafirst );
  }
});
$("#slider-year").slider({
  range: "min",
  value: 10,
  step: 1,
  min: 5,
  max: 15,
  slide: function( ev, ui ) {
    datasecond = ui.value;
    $("#yeartotal").text( ui.value );
  }
});

// you can access at any time your variables
// datafirst and datasecond and calculate whatever you need to.
Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
  • Hi, I thought that this solution is functional but now I found out that it is not function. The problem is that I can use variable datafirst and datasecond. Please can you give me some advise? Thank you for your help. – folpy Jan 19 '14 at 15:43
  • @folpy if you just say "does not work" - means nothing to me. YOu have to explain your issue in details, what you want to achieve, how you plan to use that variables , when and what for. – Roko C. Buljan Jan 19 '14 at 15:45
  • Sorry I try to write more details. I need to count this two variables into one variable. I tried to use console.log(datafirst) but in console there is no result. That is all what I know. Thank you for your help. – folpy Jan 19 '14 at 15:49
  • @folpy when you want to get that data? on some button click? On sliders scroll? when? please can you explain?? – Roko C. Buljan Jan 19 '14 at 15:52
  • I want to get this data from jquery slider form(jqueryui.com/slider/) as I wrote in my first post. – folpy Jan 19 '14 at 15:55
  • @folpy it's obvious that you want to get that data from the slider, and if you go to my demo link in my answer I've shown you how I get the values. What's your issue? I really cannot help until you explain what how and when you want that data. – Roko C. Buljan Jan 19 '14 at 16:24
  • @folpy Have you tried anything? http://jsbin.com/UqUqeni/1/edit Do you have any demo to show with your issue? – Roko C. Buljan Jan 19 '14 at 16:28
  • Thank you for your advise but in my code it doesn't work. There is demo how I am using it http://jsbin.com/uSoKOFiY/1/edit?html,js,output – folpy Jan 19 '14 at 17:13
  • @folpy your code was indicating that you don't understand where the variable is changing, you used wrong ID names etc etc. http://jsbin.com/uSoKOFiY/2/edit – Roko C. Buljan Jan 19 '14 at 21:06