0
일련의 배열을 기반으로 합계를 계산하는 기존 자바 스크립트가 있습니다. 그런 다음 스크립트는 다음과 같이 입력 필드에 합계를 배치합니다. <input name="total" type="text" class="total" onfocus="this.form.elements[0].focus()" size="10">
자바 스크립트에서 2 세금 비율로 기존 총액 계산 및 표시
합계를 취하고 계산 된 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);
}
방법 몇 가지 * 관련 * 코드를 게시 약을? – MaxArt
이것은 제가 생각한 총계를 계산합니까? 너 뭐 찾고있어? –
그것은 * 당신이 찾고있는 것보다 더 비슷합니까? Javascript 코드에 문제가 있습니까? 입력은 어디에서 할 수 있습니까? HTML 소스의 위치는 무엇입니까? – MaxArt