Código HTML:
<html>
<head>
<script type="text/javascript">
function Suma(esto,total)
{
if(esto.value=="")
{
esto.value="0";
}
if(isNaN(esto.value))
{
esto.value="0";
}
total1=parseInt(document.getElementById(total).value)+parseInt(esto.value);
document.getElementById(total).value=total1;
}
function Suma2(esto,total1,total2)
{
if(esto.value=="")
{
esto.value="0";
}
if(isNaN(esto.value))
{
esto.value="0";
}
total_=parseInt(document.getElementById(total2).value)+parseInt(esto.value);
if(total_>parseInt(document.getElementById(total1).value))
{
alert("La segunda suma es mayor");
esto.value="";
esto.focus();
}
else
{
document.getElementById(total2).value=total_;
}
}
</script>
</head>
<body>
<form name="formu">
Campo A:<input type="text" name="campoA" OnBlur="Suma(this,'total1')" />
Campo B:<input type="text" name="campoB" OnBlur="Suma(this,'total1')" />
Campo C:<input type="text" name="campoC" OnBlur="Suma(this,'total1')" />
Campo D:<input type="text" name="campoD" OnBlur="Suma(this,'total1')" />
<br /><br />
Total 1:<input type="text" name="total1" id="total1" value="0" readonly />
<br /><br/>
Campo E:<input type="text" name="campoE" OnBlur="Suma2(this,'total1','total2')" />
Campo F:<input type="text" name="campoF" OnBlur="Suma2(this,'total1','total2')" />
Campo G:<input type="text" name="campoG" OnBlur="Suma2(this,'total1','total2')" />
Campo H:<input type="text" name="campoH" OnBlur="Suma2(this,'total1','total2')" />
<br /><br/>
Total 2:<input type="text" name="total2" value="0" readonly />
</form>
</body>
</html>
aqui te he echo un ejemplo cuando pierde el foco los campos (onBlur).