Вам необходимо обновить атрибут max
слайдера внутри вашей функции getCheck()
, например:
document.getElementById('slider1').max = currentPrice;
//checkboxes and buttons
var basicPrice = 5000; // This is how we start
function getCheck() {
var currentPrice = basicPrice; // every time
currentPrice = parseFloat($(".event-hook-class.active").data("prezzo")) || basicPrice, // add any "active" boxes
services = [],
total = 0;
$("input[id^=service]").each(function() {
if (this.checked) {
total += +this.value;
services.push($("[for=" + this.id + "]").html()); // get the label text
}
});
$("#prezzo").text((currentPrice + total).toFixed(2) + "€");
$("#aaa").text((currentPrice + total).toFixed(2));
$("#serv").html("services: " + services.join(", "));
document.getElementById('slider1').max = (currentPrice + total).toFixed(2);
}
$(document).ready(function() {
$("input[id^=service]").on("click", getCheck);
$(".event-hook-class").on("click", function(e) {
e.preventDefault();
$(".event-hook-class").removeClass("active");
$(this).addClass("active")
$("#prezzo").html($(this).data('prezzo') + ' €');
$("#mq").html($(this).data('mq'));
getCheck(); // will add this and the checkboxes
});
getCheck(); // initialise on page load
});
//slider
$(document).ready(function() {
var zzz = document.getElementById('aaa').innerText;
document.getElementById('slider1').max = zzz;
});
const $mutuo = $("#mutuo"),
$rata = $("#rata"),
$anni = $("#anni"),
$slider1 = $("#slider1"),
$slider2 = $("#slider2"),
$max = $("#aaa").html();
function showAmount1(newAmount) {
document.getElementById('mutuo').innerHTML = newAmount;
$mutuo.val($("#mutuo").innerHTML);
update();
}
function showAmount2(newAmount) {
document.getElementById('anni').innerHTML = newAmount;
$anni.val($("#anni").innerHTML);
update();
}
function update() {
let interesseannuo = 1.60,
C = $mutuo.html(),
anni = $anni.html(),
i = interesseannuo / 12 / 100,
n = anni * 12,
rata = C * i / (1 - Math.pow(1 + i, -n));
$rata.html(rata.toFixed(2) + " €");
}
update();
200 €
Totale mutuo (€)
0
Durata mutuo (anni)
10
La tua rata
Хорошо, это подтверждение концепции. Просьба заметить, что это суммирует поля.
Надеюсь, теперь все стало яснее.
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>JSfiddle</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
</head>
<body>
<table>
<tr class="create-invoice-tr-body-items">
<td style="width: 12%;" class="ly-inv-preview-show-borders-cell">
<form>
<input class="inp-name" type="text" value="20" />
<input class="inp-name" type="text" value="20" />
<input class="inp-name" type="text" value="20" />
<input class="inp-name" type="text" value="20" />
<input class="inp-name" type="text" value="20" />
</form>
</td>
</tr>
</table>
</div>
<script>
$(document).ready(function () {
var sum = 0;
//perform loop accros all class elems
$('table tr td .inp-name').each(function (i, obj) {
//console.log(i, obj);
// cache varialbe
let $objVal = $(obj).val();
if ($objVal !== NaN && typeof $objVal !== "undefined") {
sum += parseFloat($objVal);
}
});
console.log(sum);
});
</script>
</body>
</html>