It is not very clear what you are trying to do with a discount.
If we follow your formula
(40 * NUMBER) - (NUMBER * 0.1)
it doesn't match example:
If the slider value equals 1 then the cost is $40
If the slider equals 2 then the value is $76
Since,
- Number = 1 -> (40 * 1) - (1 * 0.1) = 39.90
- Number = 2 -> (40 * 2) - (2 * 0.1) = 79.80
I think you really meant something like this...
(40 * NUMBER) - 0.1 * (NUMBER - 1) * 40
This will be
- Number = 1 -> (40 * 1) - 0.1 * (1 - 1) * 40 = 40
- Number = 2 -> (40 * 2) - 0.1 * (2 - 1) * 40 = 76
Is that the case?
UPDATE:
http://jsfiddle.net/kLKxX/
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Slider - Snap to increments</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#slider" ).slider({
value:1,
min: 1,
max: 100,
step: 1,
slide: function( event, ui ) {
$( "#amount" ).val( "items: " + ui.value );
$("#discounted").val("$" + calculateDiscount(ui.value, 40));
}
});
$( "#amount" ).val( "items: " + $( "#slider" ).slider( "value" ) );
});
function calculateDiscount(value,base){
var discounted = (base * value) - 0.1 * (value - 1) * base;
return discounted;
}
</script>
</head>
<body>
<p>
<label for="amount">Donation amount ($50 increments):</label>
<input type="text" id="amount" style="border:0; color:#f6931f; font-weight:bold;">
<input type="text" id="discounted" style="border:0; color:#FF0000; font-weight:bold;">
</p>
<div id="slider"></div>
</body>
</html>