Thursday, October 7, 2010

Javascript update a total field

Let's say you have a field a and a field b...
and you're using some sort of index thing because you want to keep adding additional fields ...

function updateSubtotal(e) {
var evn =
var evv = e.value
var indx = evn.substr(evn.length -1);

var st=document.getElementsByName("subtotal"+indx)[0];
var qt=document.getElementsByName("fielda"+indx)[0].value;
var ct=document.getElementsByName("fieldb"+indx)[0].value;

so if you have a field1 and field2 you can multiply it together... and it will apply for the current index level that is applied to the named field.

so ... fielda100 will multiply to fieldb100 and update subtotal100
then you'd put onBlur=updateSubtotal(this) in fielda and fieldb

No comments:

Blog Archive