http://jsfiddle.net/Slashus/wduac/46/
[計算] ボタンを削除し、ユーザーがスライダーを使用すると (「ポンド」のように)、すべての変数が画面に自動更新されるようにしようとしています。しかし、私がすることはすべて失敗します。
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ","); }
$(function () {
$("#slider-range-max").slider({
range: "max",
min: 50,
max: 20000,
value: 50,
slide: function (event, ui) {
$("#amount").val(ui.value);
}
});
$("#amount").val($("#slider-range-max").slider("value"));
$("#radio").buttonset();
$("button").button().click(function (event) {
event.preventDefault();
var value1 = parseInt($("#amount").val()); //get value of slider
var result = 0;
var radioval = $('input[name=radio]:checked', '#myForm').val();
var tons = (value1 / 2000).toFixed(1);
//By the pound bulk prices
if (radioval == "handpicked" && value1 < 2000) result = value1 * 7.50;
else if (radioval == "minerun" && value1 < 2000) result = value1 * 4.50;
else if (radioval == "hematitemix" && value1 < 2000) result = value1 * 3.50;
//By the ton bulk prices
else if (radioval == "handpicked" && value1 > 2000) result = value1 * 5.99;
else if (radioval == "minerun" && value1 > 2000) result = value1 * 3.99;
else if (radioval == "hematitemix" && value1 > 2000) result = value1 * 2.99;
//Show Results
var perpoundamt = (result / value1).toFixed(2);
var finalcostraw = Math.round(result);
var finalcost = numberWithCommas(finalcostraw);
$("#resultlabel").text("Result: " + "$" + finalcost); //show result
$("#perpoundlabel").text("Per Pound " + "$" + perpoundamt); //show result
$("#tonslabel").text("Number of tons " + tons); //show result
});
});