folpy
folpy

Reputation: 149

Jquery function parameter

I have problem with jquery function. I am trying to work with variable from jquery form slider and I have this script.

$(document).ready(function () {

$("#slider-amount").slider({
  range: "min",
  value: 10,
  step: 10000,
  min: 100000,
  max: 1000000,
  slide: function( ev, ui ) {
    var amountValue = ui.value;
    $("#amount").text(ui.value);
    process(amountValue);
  }
 });

$("#slider-year").slider({
  range: "min",
  value: 10,
  step: 1,
  min: 5,
  max: 15,
  slide: function( ev, ui ) {
    var yearSlider = ui.value;
    $("#year").text( ui.value );
    process(yearSlider);
  }
});

function process(yearSlider, amountValue){
    var valueFromSlider = amountValue;
    console.log(valueFromSlider);
    if(lc_jqpost_info[valueFromSlider] !== undefined) {
     document.getElementById("vypocet_splatka").innerHTML = lc_jqpost_info[valueFromSlider];
    };
}

});

The problem is that in console work only yearSlider value and second amountValue show status undefinated.

Thank you for your help.

Upvotes: 0

Views: 116

Answers (1)

anderssonola
anderssonola

Reputation: 2195

One way to do it could be to access the values from the DOM:

function process(){
    var yearVal = $("#year").text();
    var amountVal = $("#amount").text();
    /*rest of your code*/
}

Another is to get it from the slider:

function process(){
    var yearVal = $("#year").slider().data().uiSlider.value();
    var amountVal = $("#amount").slider().data().uiSlider.value();
    /*rest of your code*/
}

Upvotes: 1

Related Questions