Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calc function not setting value

Status
Not open for further replies.

mickeyg

Technical User
Joined
Mar 30, 2001
Messages
120
Location
US
I have an order form with about 10 line items and am trying to write a reusable function for line price calculating. I pass in the price and fieldname prefix to my function, but it is not updating my 'total' field. It only updates the 'total' field when I hard code the left hand side of the assigment (see commented out line below).

I thought this had something to do with eval(), but have not been able to get that to fix it.

form fields:
<input type=&quot;text&quot; name=&quot;chunkqty&quot; size=&quot;10&quot; onblur=&quot;calcsubtotal('3.25','chunk')&quot;/>
<input type=&quot;text&quot; name=&quot;chunktotal&quot; size=&quot;7&quot; />

function calcsubtotal(unitprice,productname) {
var myform = 'document.mglures.';
var subtotal;
var qtywidget = myform + [productname] + 'qty.value';
var totalwidget = myform + [productname] + 'total.value';

subtotal = [unitprice] * eval(qtywidget);
// update subtotal value
//document.mglures.chunktotal.value = subtotal;
totalwidget = subtotal;
}

Thanks,
Mickey
 
Hi, I have a add script on my site, take a look maybe that can help you...
In the search box type in 'add' and take a look at the script... Forget the Nobel Peace prize, I just want to take over the world!! [hammer]
 
Mickey,

your original code is pretty close aside from a few syntax errors...try this:

function calcsubtotal(unitprice, productname) {
var myform = document.mglures;
var subtotal;
var qtywidget = myform[productname + 'qty'];
var totalwidget = myform[productname + 'total'];

subtotal = unitprice * qtywidget.value;
totalwidget.value = subtotal;
}

=========================================================
while (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top