Forum Moderators: open
I am having mulitple textboxes, where numerals and fed and onBlur of each text box, the value gets added and is displayed in a text box at bottom...
Now, if i enter once and mov down the form , addition is alright...
But , if i move up again, and want to change the value of a textbox, the final total should also reflect the latest addition...
Also, if it reaches zero and then again ifi change, it should reflect latest changes
Help Please
function doTotals(){
var theTotal,fld;
for (var x=0;x<document.forms[0].elements.length;x++){
fld = document.forms[0].elements[x];
if(fld.type == "text"){
if(!isNaN(fld.value)){
theTotal += fld.value;
}
}
}
document.forms[0].totalfieldname.value = theTotal;
}
that might work..
[pre]
---- HTML ----
<form ....
<input onblur="doTotals(this.form)" .... />
</form> ---- JS ----
function doTotals(form){
var theTotal=0,fld;
for (var x=0;x<form.elements.length;x++){
fld = form.elements[x];
if(fld.type == "text" &&!isNaN(fld.value)){
theTotal += fld.value;
}
}
form.totalfieldname.value = theTotal;
}
[/pre]