Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help me, please...

Status
Not open for further replies.

GUJUm0deL

Programmer
Jan 16, 2001
3,676
US
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=&quot; &quot;
document.addem.input2.value=&quot; &quot;
document.addem.input3.value=&quot; &quot;
document.addem.input4.value=&quot; &quot;
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 = &quot;&quot;
var Outdollars = &quot;&quot;
var decimalpos = valuein.indexOf(&quot;.&quot;)
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 = &quot;,&quot; + tDollars + Outdollars
dollen = dollen - 3
} else {
Outdolars = tDollars + Outdollars
dollen = 0
}
}
if (Outdollars.substring(0,1) == &quot;.&quot;)
dollars = Outdollars.substring(1,Outdollars.length)
else
dollars = Outdollars
}
var cents = valuein.substring(decimalpos+1, decimalpos+3)
if (cents == &quot;&quot;)
cents = &quot;00&quot;
var formatstr = &quot;$&quot; + dollars + &quot;.&quot; + 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=&quot;addem&quot;>
addend1:
<INPUT TYPE=&quot;TEXT Area&quot; NAME=&quot;input1&quot; onChange=&quot;addition(addem)&quot;>
<P>addend2:
<INPUT TYPE=&quot;TEXT Area&quot; NAME=&quot;input2&quot; onChange=&quot;addition(addem)&quot;>
<P>addend3:
<input type=&quot;text Area&quot; name=&quot;input3&quot; onChange=&quot;addition(addem)&quot;>
<P>addend4 :
<input type=&quot;text Area&quot; name=&quot;input4&quot; onChange=&quot;addition(addem)&quot;>
<p>answer:
<INPUT TYPE=&quot;TEXT Area&quot; NAME=&quot;answer&quot; onFocus=&quot;this.blur();&quot;>
<p>&amp;nbsp;
</FORM>
</center>
</BODY>
</HTML>

this is the site where i put the code:

Anyone know what the problem is??
 
one problem is:
TYPE=&quot;TEXT Area&quot; isn't a valid input type.

try input type=&quot;text&quot; adam@aauser.com
 
i changed the addthem function, because the blank fields are being converted to Not A Number when they are being added:

function addthem() {
var add1 = document.addem.input1.value
var add1 = parseInt(add1, 10)
add1 = (isNaN(add1))?0:add1;
var add2 = document.addem.input2.value
var add2 = parseInt(add2, 10)
add2 = (isNaN(add2))?0:add2;
var add3 = document.addem.input3.value
var add3 = parseInt(add3, 10)
add3 = (isNaN(add3))?0:add3;
var add4 = document.addem.input4.value
var add4 = parseInt(add4, 10)
add4 = (isNaN(add4))?0:add4;
return eval(add1) + eval(add2) + eval(add3) + eval(add4);
}

notice the bold line above jared@aauser.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top