<script language="javascript" type="text/javascript">
function addthem() {
//ADD FIRST INPUT VALUE
var add1 = document.addem.input1.value
var add1 = parseFloat(add1, 10)
add1 = (isNaN(add1))?0:add1;
//ADD SECOND INPUT VALUE
var add2 = document.addem.input2.value
var add2 = parseFloat(add2, 10)
add2 = (isNaN(add2))?0:add2;
//ADD THEM TOGETHER
return eval(add1) + eval(add2);
}
function subtractthem() {
//SUBTRACT FIRST INPUT VALUE
var add01 = document.addem.input01.value
var add01 = parseFloat(add01, 10)
add01 = (isNaN(add01))?0:add01;
//SUBTRACT SECOND INPUT VALUE
var add02 = document.addem.input02.value
var add02 = parseFloat(add02, 10)
add02 = (isNaN(add02))?0:add02;
//SUBTRACT THEM TOGETHER
return eval(add01) + eval(add02);
}
//FUNCTION WILL PARSE THE TOTAL AS DOLLAR FORMAT
function dollarformat(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num)) num = "0";
cents = Math.floor((num*100+0.5)%100);
num = Math.floor((num*100+0.5)/100).toString();
if(cents < 10) cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
return ('$' + num + '.' + cents);
}
//CALCUATES THE ADD/SUBTRACT VALUES
function calculate() {
var x = addthem()
var y = subtractthem()
if(x>y) {
max = x+y
document.addem.total.value = dollarformat(max)
}
if(x<y) {
max = dollarformat(y-x)
max = "-" + max
document.addem.total.value = max
}
if (x==y) {
max = x-y
document.addem.total.value = dollarformat(max)
}
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.