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> </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>
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> </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>