I added the modified code leaving the reference number to 1 but nothing happens on my form. I am missing something.
js code
if(typeof(N) != "function") function N($n, $d) { return ($d) ? Number($n).toFixed($d).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : $n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }
function Calculate(frm) {
var order_total, length, width, i;
order_total = 0;
length = parseFloat(frm.length.value);
width = parseFloat(frm.width.value);
if(length > 0 && width > 0) {
order_total = length * width;
for(i = 0; i < frm.tooling.length; i++) {
if (frm.tooling[i].value === "withouttooling" && frm.tooling[i].checked === true) order_total = order_total * ".35";
if (frm.tooling[i].value === "withtooling" && frm.tooling[i].checked === true) order_total = order_total * ".45";
}
//order_total = order_total * .35
order_total = order_total
} else {
order_total = 0;
}
// Display the total rounded to two decimal places
//frm.totalcost.value = '$ ' + round_decimals(order_total, 2);
frm.totalcost.value = '$' + _N(order_total, 2);
_CalculateTotal(frm);
}
function Calculateitem2(frm) {
var order_total, length, width, i;
order_total = 0;
length = parseFloat(frm.length2.value);
width = parseFloat(frm.width2.value);
if(length > 0 && width > 0) {
order_total = length * width;
for(i = 0; i < frm.tooling2.length; i++) {
if(frm.tooling2[i].value === "withouttooling" && frm.tooling2[i].checked === true) order_total = order_total * ".35";
if(frm.tooling2[i].value === "withtooling" && frm.tooling2[i].checked === true) order_total = order_total * ".45";
}
//order_total2 = order_total2 * .35
order_total = order_total;
} else {
order_total = 0;
}
// Display the total rounded to two decimal places
//frm.totalcost2.value = '$ ' + round_decimals(order_total, 2);
frm.totalcost2.value = '$' + _N(order_total, 2);
_CalculateTotal(frm);
}
function CalculateTotal($f) {
var $total1 = parseFloat($f.totalcost.value.replace(/[0-9.]/g, ""));
var $total2 = parseFloat($f.totalcost2.value.replace(/[0-9.]/g, ""));
console.log($total1, $total2);
document.getElementById("grandTotal").innerHTML = (!isNaN($total1) && !isNaN($total2)) ? "$" + N($total1 + $total2, 2) : "";
}
function round_decimals(original_number, decimals) {
var result1 = original_number * Math.pow(10, decimals);
var result2 = Math.round(result1);
var result3 = result2 / Math.pow(10, decimals);
return pad_with_zeros(result3, decimals);
}
function pad_with_zeros(rounded_value, decimal_places) {
// Convert the number to a string
var value_string = rounded_value.toString();
// Locate the decimal point
var decimal_location = value_string.indexOf(".");
// Is there a decimal point?
if(decimal_location == -1) {
// If no, then all decimal places will be padded with 0s
decimal_part_length = 0;
// If decimal_places is greater than zero, tack on a decimal point
value_string += decimal_places > 0 ? "." : "";
} else {
// If yes, then only the extra decimal places will be padded with 0s
decimal_part_length = value_string.length - decimal_location - 1;
}
// Calculate the number of decimal places that need to be padded with 0s
var pad_total = decimal_places - decimal_part_length;
if(pad_total > 0) {
// Pad the string with 0s
for(var counter = 1; counter <= pad_total; counter++) {
value_string += "0";
}
}
return value_string;
}
if(typeof(N) != "function") function N($n, $d) { return ($d) ? Number($n).toFixed($d).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : $n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }
$itemCount = 2;
$lFields = ["length", "length2", "length3", "length4"];
$wFields = ["width", "width2", "width3", "width4"];
$tFields = ["totalcost", "totalcost2", "totalcost3", "totalcost4"];
function Calculate($a) {
var order_total, length, width, i;
order_total = 0;
length = parseFloat(document.forms[1][$lFields[$a]].value);
width = parseFloat(document.forms[1][$wFields[$a]].width.value);
if(length > 0 && width > 0) {
order_total = length * width;
for(i = 0; i < document.forms[1]["tooling"].length; i++) {
if (document.forms[1]["tooling"][i].value === "withouttooling" && document.forms[1]["tooling"][i].checked === true) order_total = order_total * ".30";
if (document.forms[1]["tooling"][i].value === "withtooling" && document.forms[1]["tooling"][i].checked === true) order_total = order_total * ".40";
}
//order_total = order_total * .35
order_total = order_total + 25;
} else {
order_total = 0;
}
// Display the total rounded to two decimal places
//frm.totalcost.value = '$ ' + round_decimals(order_total, 2);
document.forms[1]["totalcost"].value = '$' + _N(order_total, 2);
_CalculateTotal();
}
function CalculateTotal() {
var $grandTotal = 0;
var $f = document.forms[1];
for(var $i = 0; $i < $itemCount; $i++) {
$grandTotal = ($grandTotal) + parseFloat($f[$tFields[$i]].value.replace(/[0-9.]/g, ""));
}
document.getElementById("grandTotal").innerHTML = N($grandTotal, 2);
}
form same as before but input length and width replaced as referenced above.
http://www.webcrawldesigns.com/dct/order-form-test/
thx