auto calculation not working

hi,
Auto calculation not working in my file.. i need a output of (a+b)= amount..a-b,a*b,a/b always working, but a+b not working..
plz help me.i insert in my code
 calc.html
codeoxygenAsked:
Who is Participating?
 
Gurvinder Pal SinghCommented:
what did you entered in textboxes?
0
 
Gurvinder Pal SinghCommented:
does it have any stylesheet also?

check this code though
<html>
<head>
<script type="text/javascript">
	var total = 0;
	function getValues() 
	{
		var qty = 0;
		var rate = 0;
		var obj = document.getElementsByTagName("input");
		for(var i=0; i<obj.length; i++)
		{
			total = parseInt(total);
			if(obj[i].name == "qty"){qty = obj[i].value;}
			if(obj[i].name == "rate"){rate = obj[i].value;}
			if(obj[i].name == "amt")
			{
	          	if(qty > 0 && rate > 0)
				{
					obj[i].value = parseInt( qty ) + parseInt( rate );
				}
				else
				{
					obj[i].value = parseInt( qty ) + parseInt( rate );
				}
			}
		}
	}

</script>

</head>
<body>
<form name="gr" method="post">


<table width="38%" align="center" cellpadding="0" cellspacing="0" class="normal-text" border="0">
<tr>
<td width="20"></td>
<td width="80" class="forhead" style="white-space:nowrap;">A</td>
<td width="80" class="forhead" style="white-space:nowrap;">B</td>
<td width="80" class="forhead" style="white-space:nowrap;">Amount</td>

</tr>
</table>
<table border="0" id="dataTable" width="38%" align="center" cellpadding="0" cellspacing="0" class="normal-text">
<tr>

<td class="forhead" style="white-space:nowrap;" width="80"><input type="text"  name="qty"  onkeyup="getValues()" style="width:80px;" onBlur="getValues()" value="0"></td>
<td class="forhead" style="white-space:nowrap;" width="80"><input type="text"  name="rate" onKeyUp="getValues()" style="width:80px;" onBlur="getValues()" value="0"></td>
<td class="forhead" style="white-space:nowrap;" width="80"><input type="text"  name="amt" style="width:80px;" 
onKeyUp="getValues()"  value="0"></td>

</tr>
</table>
</form>
</body>
</html>

Open in new window

0
 
codeoxygenAuthor Commented:
a+b result not display correctly.
0
 
codeoxygenAuthor Commented:
working.
0
 
codeoxygenAuthor Commented:
thanks. working good
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.