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

add 2 decimal numbers

Status
Not open for further replies.

oshjosh

Technical User
Mar 11, 2002
34
0
0
TH
Hi
I have a small javascript that adds 2 form fields, however when I add decimal numbers it only adds the integers rather than the whole decimal number. Any suggestions greatly welcomed.

Script is below.

Cheers
Rob

<script language="JAVASCRIPT">
<!--
function addTWD() {
document.TWDform.Num3.value =
parseInt(document.TWDform.Num1.value) +
parseInt(document.TWDform.Num2.value);
}
//-->
</script>
<form name="TWDform">
<table>
<tr>
<td colspan="2" align="CENTER"><b>Add two numbers
with Javascript</b></td>
</tr>
<tr>
<td>First Number:</td>
<td><input type="TEXT" name="Num1" value=""></td>
</tr>
<tr>
<td>Second Number:</td>
<td><input type="TEXT" name="Num2" value=""></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input type="BUTTON" name="AddButton" value="Add
the numbers"
onclick="JavaScript:addTWD(); true;">
<input type="RESET"></td>
</tr>
<tr>
<td>Total:</td>
<td><input type="TEXT" name="Num3" value=""></td>
</tr>
</table>
</form>
 
Dan

Thank you for the fast response worked a dream

Cheers
Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top