单个选定项目的总和正在运行,但我不知道如何连接"默认价格" (我用于演示)到" Total"其余的计算(税收和折扣)。
function chaked1() {
$("#filled-in-box1").click(function(event) {
if (this.checked) {
document.getElementById("one").value = document.getElementById("filled-in-box1").value;
document.getElementById('one').readOnly = false;
} else {
document.getElementById("one").value = "0";
document.getElementById('one').readOnly = true;
}
});
}
function chaked2() {
$("#filled-in-box2").click(function(event) {
if (this.checked) {
document.getElementById("two").value = document.getElementById("filled-in-box2").value;
document.getElementById('two').readOnly = false;
} else {
document.getElementById("two").value = "0";
document.getElementById('two').readOnly = true;
}
});
}
$(".tot_amount").click(function(event) {
var total = 0;
$(".tot_amount:checked").each(function() {
total += parseInt($(this).val());
});
if (total == 0) {
$('#cost').val('');
} else {
$('#cost').val(total);
}
});
function updateInput() {
var discount = document.getElementsByName("discount")[0].value;
var cost = document.getElementsByName("cost")[0].value;
document.getElementsByName("price")[0].value = cost - (cost * (discount / 100));
var taxes = document.getElementsByName("taxes")[0].value; // <======================
if (isNaN(taxes)) // IF "no taxes" IS SELECTED...
document.getElementsByName("ttaxes")[0].value = 0;
else {
cost = document.getElementsByName("price")[0].value;
document.getElementsByName("ttaxes")[0].value = (cost * (taxes / 100));
}
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>
<input type="checkbox" class="tot_amount" value="10" id="filled-in-box1" onclick="chaked1();">10
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="tot_amount" value="20" id="filled-in-box1" onclick="chaked1();">20
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="tot_amount" value="30" id="filled-in-box1" onclick="chaked1();">30
</td>
</tr>
<tr></tr>
<tr>
<td>Total
<input type="text" id="cost" readonly>
</td>
</tr>
<tr>
<td width="98">Taxes</td>
<td width="115">Discount</td>
<td width="118">Default price</td>
</tr>
<tr>
<td>
<select class="select" name="taxes" onChange="updateInput()">
<option value="no" selected>no taxes</option>
<option value="19">19% taxes</option>
<!-- <====================== -->
</select>
</td>
<td>
<select class="select" name="discount" onChange="updateInput()">
<option value="0" selected>0% discount</option>
<option value="5">5% discount</option>
<option value="10">10% discount</option>
<option value="20">20% discount</option>
</select>
</td>
<td>
<input type="text" class="select" name="cost" id="cost" value="1000">
</td>
</tr>
<tr>
<td>Price after discount</td>
<td>Taxes</td>
<td> </td>
</tr>
<tr>
<td>
<input type="text" name="price" value="0">
</td>
<td>
<input type="text" name="ttaxes" value="0">
</td>
<!-- <====================== -->
</tr>
</table>
&#13;