TextBox Values Added

[Total: 0    Average: 0/5]

This example will sum up integer values in text boxes.

Body Code:

<script> 
function soma(){ 
var vtemp=0 
vresult=0 
for (var i=1;i<5;i++){ // loop to get all inputs 
vtemp=eval("parseFloat(document.all.box"+i+".value)") 
if(!isNaN(vtemp)) vresult+=vtemp // if value is a number - add it. 
} 
document.all.result.value=vresult // change the last input...Result one 
} 
</script> 
<body> 
<form> 
<input name=box1 onchange="soma()"> 
<input name=box2 onchange="soma()"> 
<input name=box3 onblur="soma()"> 
<input name=box4 onblur="soma()"><br> 
SUM:<input name=result > 
</form> 

Times Viewed: 6

Leave a Reply

Your email address will not be published. Required fields are marked *