I am using three javascript function to sum of input field values. But the first two function is working well but the third function is not working.
here is my javascripts:
<script language="javascript">
function addNumbers()
{
var val1 = parseInt(document.getElementById("ot").value);
var val2 = parseInt(40);
var ansD = document.getElementById("totalot");
ansD.value = val1 * val2;
}
function addSecincome(){
var val1 = parseInt(document.getElementById("totalot").value);
var val2 = parseInt(document.getElementById("mc").value);
var val3 = parseInt("1024");
var ansD = document.getElementById("secincome");
ansD.value = val3 * val1 + val2;
}
function addIncome(){
var val1 = parseInt(document.form.getElementById("totalot").value);
var val2 = parseInt("150");
var ansD = document.form.getElementById("INC");
ansD.value = val2 * val1 ;
}
</script>
Here is my html codes:
<tr height="20">
<td height="20">BUYER</td>
<td colspan="3"><input type="text" name="buyer" value=" " /></td>
<td>OT</td>
<td><input id="ot" type="text" name="ot" value="" /></td>
<td><input type="text" id="totalot" name="totalot" onclick="javascript:addNumbers()" value="" /></td>
<td>MC</td>
<td><input id="mc" type="text" name="mc" value="" /></td>
<td colspan="2"><input id="secincome" type="text" onclick="javascript:addSecincome()" name="2ndincome" value="" /></td>
<td>SMV</td>
<td><input type="text" name="smv" value= " " /></td>
<td>O/QTY</td>
<td><input type="text" name="oqyt" value=" " /></td>
<td>TTL AVG</td>
<td><input type="text" name="planeffi" value=" " /></td>
</tr>
<tr height="20">
<td height="20">DAY INPUT</td>
<td colspan="3"><input type="text" name="dayinput" value=" " /></td>
<td colspan="2">PLAN HOUR</td>
<td> <input type="text" name="planhour" vaue="10" /></td>
<td colspan="2">PRO/LOSS</td>
<td colspan="2"><input id="ploss" type="text" onclick="javascript:pp();" name="proloss" value="" /></td>
<td>TGT</td>
<td>T/TGT</td>
<td>CUTTING</td>
<td><input type="text" name="cutting" value=" " /></td>
<td rowspan="2"><input type="text" name="ttlavg" value=" " /></td>
<td> </td>
</tr>
Though the functions syntex is same the third function is not working for me. I have tried with different input id but it is not working for me. but the first two function is working . I don't understand about this issu and i don't have this kind of problem before.
Need your help thanks.
document.form.getElementByIdand not realize it is the difference between your working functions and your failing one? Also, checking your console for errors should be the first step you take when things don't work the way you want them.