在Javascript中计算并显示具有2个税收百分比的现有总值
Calculate and Display existing Total value with 2 tax percentages in Javascript
我有一个现有的javascript,它基于一系列数组计算总数。然后,脚本将总数放在一个输入字段中,如下所示:<input name="total" type="text" class="total" onfocus="this.form.elements[0].focus()" size="10">
如何添加两个附加值,以获取总计并显示计算了6%和7%税款的值?
function calculatetotal() {
var order_total = new Number();
order_total = 0;
var item_price = new Number();
var item_quantity = new Number();
// Run through all the form fields
for (var i=0; i < document.form1.elements.length; ++i) {
// Get the current field
form_field = document.form1.elements[i];
// Get the field's name
form_name = form_field.name;
// Is it a "category" field?
if (form_name.substring(0,3) == "CAT") {
var adjust_check = check_price_adjustment(form_name);
if (adjust_check) {
item_price = form_field.value;
} else {
item_price = 0;
}
} else if (form_name.substring(0,4) == "PROD") { // Is it a "product" field?
// Is the major category of this product checked?
var category = "CAT_" + form_name.substring(5,7);
var cat_box = document.getElementById(category);
if (cat_box.type=="checkbox" && cat_box.checked) {
// If so, extract the price from the form field value
item_price = form_field.value;
// reset negative item prices to 0
if (item_price < 0) {
item_price = 0;
}
} else if (cat_box.type.indexOf("select")!=-1) {
// If so, extract the price from the form field value
item_price = form_field.value;
// reset negative item prices to 0
if (item_price < 0) {
item_price = 0;
}
} else {
// Price is set to zero
item_price = 0;
}
} else {
item_price = 0;
}
// Get the quantity
if (form_field.type=="checkbox") {
if (form_field.checked) {
item_quantity = 1;
} else {
item_quantity = 0;
}
} else if (form_field.type.indexOf("select")!=-1) {
item_quantity = 1;
} else if (form_field.type=="hidden") {
item_quantity = 1;
}
if (form_name == "CAT_EX")
item_price = 0;
// Update the order total
if (item_quantity >= 0) {
order_total += item_quantity * item_price;
}
}
// Display the total rounded to two decimal places
document.form1.total.value = round_decimals(order_total, 2);
}
我在这里添加了额外的表单元素和计算:
document.form1.total.value = round_decimals(order_total, 2);
document.form1.totalsix.value = order_total * .085;
document.form1.totalseven.value = round_decimals(order_total * .09, 2);
然后添加以下输入:
<p>$<input name="totalsix" type="text" value="" onfocus="this.form.elements[0].focus()" size="10"></p>
<p>$<input name="totalseven" type="text" value="" onfocus="this.form.elements[0].focus()" size="10"></p>
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- 在Javascript中计算并显示具有2个税收百分比的现有总值
- 计算HTML表TD中两个数字之间的百分比
- 如何在javascript中计算两个变量的百分比
- JavaScript 在两个输入中计算错误的百分比
- 在谷歌地图 JS API 上获取两个点之间的点的纬度和经度(按百分比)
- Highstock.js:无法创建具有两个堆积柱形图的多窗格图表,一个是“正常”,另一个是“百分比”
- 根据百分比计算两个坐标之间的点
- 将三个值在一定百分比内进行比较
- 我如何得到2个数字的百分比
- JQuery -在变化时用另一个输入的百分比倍数填充两个输入
- 用JavaScript数组在字符串中添加两个字母的百分比
- 两个值之间的百分比差
- JavaScript-将3个数字转换为百分比,没有't总收率为100%
- 计算for循环中JSON中两个值之间的百分比
- 输入两个百分比,给我第三个
- Javascript逻辑获取两个数字之间每个数字的百分比
- 在JavaScript中计算两个多边形的重叠百分比
- 使用Javascript计算多个动态值的百分比变化
- 用三个数字创建一个百分比