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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script concatenates numbers instead of adding them 1

Status
Not open for further replies.

Muddsnapper

Programmer
Apr 24, 2007
2
US

The script concatenates the 2 numbers before dividing by 2 instead of adding them.

here's the code:

Code:
<SCRIPT LANGUAGE="JavaScript">

function Calc(){
 
document.autoSumForm.totalBox.value=(document.autoSumForm.weight1.value + document.autoSumForm.rating1.value)/2

}

</script>



</head>

<body>
 <form action="test.htm" method="post" name="autoSumForm">
<table width="200" border="1">
<tr><td>
<input type="Text" name="weight1" size="5" onBlur="Calc();" >
</td><td>
<input type="Text" name="rating1" size="5" onBlur="Calc();">
</td></tr>
<tr bgcolor="CCCCCC">
<td valign="top" align="right"><b>Score:</b> <i>(automatically calculated)&nbsp;</i>  
<td colspan="2"><input name="totalBox" type="text"  onfocus="this.blur()"></td></tr>
</form>
</table>
</body>
</html>
 
Code:
document.autoSumForm.totalBox.value=([!]parseInt([/!]document.autoSumForm.weight1.value[!], 10)[/!] + [!]parseInt([/!]document.autoSumForm.rating1.value[!], 10)[/!])/2

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top