I have the following code which I'm using to calculate the price of a service based on the sliders value.
It works well except the PriceVal
doesn't update in real-time. It only updates once the user has lifted the mouse click from the slider.
Does anyone know how I can get it to update in real-time as the slider slides?
The page can be viewed at http://www.voxlogic.net/pricing/
$(function() {
//document.getElementById("f1").reset();
$(":range").rangeinput({ progress: true, max: 100, value:1 });
$(":range").change(function(){
var sliderVal = this.value;
calculatePrice(sliderVal);
});
$(":range").keyup(function(){
var sliderVal = this.value;
if (sliderVal==""){
$("#priceVal").html('');
}
else
{
//check if value is from 1..25 range and correct otherwise
if (isNaN(sliderVal)){sliderVal=1;}
if (sliderVal<1){sliderVal=1;}
if (sliderVal>25){sliderVal=25;}
this.value = sliderVal;
calculatePrice(sliderVal);
}
});
$(":range").keydown(function(){
var sliderVal = this.value;
calculatePrice(sliderVal);
});
});
function calculatePrice(sliderVal){
if (isNaN(sliderVal)){sliderVal=1;}
if (sliderVal<1){sliderVal=1;}
if (sliderVal>25){sliderVal=25;}
var priceVal;
if (sliderVal<=9){
priceVal = sliderVal*6;
}
else if ((sliderVal>9)&&(sliderVal<=19)){
priceVal = 9 * 6 + (sliderVal-9) * 4.5;
}
else if (sliderVal>19){
priceVal = 9 * 6 + 10 * 4.5 + (sliderVal-19) * 3.6;
}
$("#priceVal").html('£'+priceVal.toFixed(2));
}
});