The problem is that when u input the values in add1, add2, add3, add4 the result should automaticaly display in answer. Only half the result displays. This is the site, please tell me what's wrong. Another thing is that when you input one value the answer should display that number entered, in my script it displays "isNaN", why does it do that? Thanks a whole lot.
This is the code...
<HTML>
<HEAD>
<title>adding example</title>
<SCRIPT>
<!--
function addd() {
document.addem.input1.value=" "
document.addem.input2.value=" "
document.addem.input3.value=" "
document.addem.input4.value=" "
document.addem.input1.focus()
}
function addthem() {
var add1 = document.addem.input1.value
var add1 = parseInt(add1, 10)
var add2 = document.addem.input2.value
var add2 = parseInt(add2, 10)
var add3 = document.addem.input3.value
var add3 = parseInt(add3, 10)
var add4 = document.addem.input4.value
var add4 = parseInt(add4, 10)
return eval(add1) + eval(add2) + eval(add3) + eval(add4);
}
function dollarformat(valuein) {
var formatStr = ""
var Outdollars = ""
var decimalpos = valuein.indexOf("."
if (decimalpos == -1)
decimalpos = valuein.length
var dollars = valuein.substring(0, decimalpos)
var dollen = dollars.length
if (dollen > 3) {
while (dollen > 0) {
tDollars = dollars.substring(dollen-3, dollen)
if (tDollars.length == 3) {
Outdollars = "," + tDollars + Outdollars
dollen = dollen - 3
} else {
Outdolars = tDollars + Outdollars
dollen = 0
}
}
if (Outdollars.substring(0,1) == "."
dollars = Outdollars.substring(1,Outdollars.length)
else
dollars = Outdollars
}
var cents = valuein.substring(decimalpos+1, decimalpos+3)
if (cents == ""
cents = "00"
var formatstr = "$" + dollars + "." + cents
return formatstr
}
function addition() {
document.addem.answer.value = addthem()
document.addem.answer.value = dollarformat(document.addem.answer.value)
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<center>
<FORM NAME="addem">
addend1:
<INPUT TYPE="TEXT Area" NAME="input1" onChange="addition(addem)">
<P>addend2:
<INPUT TYPE="TEXT Area" NAME="input2" onChange="addition(addem)">
<P>addend3:
<input type="text Area" name="input3" onChange="addition(addem)">
<P>addend4 :
<input type="text Area" name="input4" onChange="addition(addem)">
<p>answer:
<INPUT TYPE="TEXT Area" NAME="answer" onFocus="this.blur();">
<p>&nbsp;
</FORM>
</center>
</BODY>
</HTML>
this is the site where i put the code:
Anyone know what the problem is??
This is the code...
<HTML>
<HEAD>
<title>adding example</title>
<SCRIPT>
<!--
function addd() {
document.addem.input1.value=" "
document.addem.input2.value=" "
document.addem.input3.value=" "
document.addem.input4.value=" "
document.addem.input1.focus()
}
function addthem() {
var add1 = document.addem.input1.value
var add1 = parseInt(add1, 10)
var add2 = document.addem.input2.value
var add2 = parseInt(add2, 10)
var add3 = document.addem.input3.value
var add3 = parseInt(add3, 10)
var add4 = document.addem.input4.value
var add4 = parseInt(add4, 10)
return eval(add1) + eval(add2) + eval(add3) + eval(add4);
}
function dollarformat(valuein) {
var formatStr = ""
var Outdollars = ""
var decimalpos = valuein.indexOf("."
if (decimalpos == -1)
decimalpos = valuein.length
var dollars = valuein.substring(0, decimalpos)
var dollen = dollars.length
if (dollen > 3) {
while (dollen > 0) {
tDollars = dollars.substring(dollen-3, dollen)
if (tDollars.length == 3) {
Outdollars = "," + tDollars + Outdollars
dollen = dollen - 3
} else {
Outdolars = tDollars + Outdollars
dollen = 0
}
}
if (Outdollars.substring(0,1) == "."
dollars = Outdollars.substring(1,Outdollars.length)
else
dollars = Outdollars
}
var cents = valuein.substring(decimalpos+1, decimalpos+3)
if (cents == ""
cents = "00"
var formatstr = "$" + dollars + "." + cents
return formatstr
}
function addition() {
document.addem.answer.value = addthem()
document.addem.answer.value = dollarformat(document.addem.answer.value)
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<center>
<FORM NAME="addem">
addend1:
<INPUT TYPE="TEXT Area" NAME="input1" onChange="addition(addem)">
<P>addend2:
<INPUT TYPE="TEXT Area" NAME="input2" onChange="addition(addem)">
<P>addend3:
<input type="text Area" name="input3" onChange="addition(addem)">
<P>addend4 :
<input type="text Area" name="input4" onChange="addition(addem)">
<p>answer:
<INPUT TYPE="TEXT Area" NAME="answer" onFocus="this.blur();">
<p>&nbsp;
</FORM>
</center>
</BODY>
</HTML>
this is the site where i put the code:
Anyone know what the problem is??