<input TYPE="button"
onClick="recalc(orderform)
Main Topics
Browse All Topicswell, hope everyone is having a good holiday season...
i need to make a loop to multiply a value of a textarea to a predefined variable, ans take the sum of the loop and display it in a textarea...
i can do the math part- but the loop is making me crazy...
<script language="JavaScript">
<!-- // cloak
var vals = new Array(43.5,43.5,27.5,23,7,
function recalc(orderform) {
var orderTotal = 0;
var theVal = 0;
for(var i = 0; i < vals.length; i++) {
theVal = parseInt(orderform.element
orderform.elements['s'+(i+
orderTotal += theVal;
}
orderform.totalOrder.value
}
// uncloak -->
T1-T23 are the text areas for the input(quantity)
i had an earlier version that used "s" for the multiplication factor...
form name="orderfrom"
was ist nicht richtig?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Try this
var orderTotal = 0;
var theVal = 0;
var theTElement;
var theSElement;
for(var i = 0; i < vals.length; i++) {
theTElement = eval('orderform.' + 'T' + (i+1));
theVal = parseInt(theElement.value)
theSElement = eval('orderform.' + 's' + (i+1));
theSElement.value = theVal;
orderTotal += theVal;
}
orderform.totalOrder.value
}
And you really ought to add some error checking on the input fields before processing them (isNaN, etc).
Rob
this is where i show my js education...
i put that script within the function (recalc){}
ex.
<!-- // cloak
var vals = new Array(43.5,43.5,27.5,23,7,
function recalc(orderform) {
var orderTotal = 0;
var theVal = 0;
var theTElement;
var theSElement;
for(var i = 0; i < vals.length; i++) {
theTElement = eval('orderform.' + 'T' + (i+1));
theVal = parseInt(theElement.value)
theSElement = eval('orderform.' + 's' + (i+1));
theSElement.value = theVal;
orderTotal += theVal;
}
orderform.totalOrder.value
}
}
orderform.totalOrder.value
}
// uncloak -->
why won't this dang-blasted script run w/o an error
textareas all start "T" and then a num1-23
text area totalOrder=display of final price(s)
help!! im starting to look at the window....
<script language="JavaScript"><!--
var vals = new Array(32.63,32.63,20.63,17
function recalc(orderform) {
var orderTotal = 0;
var theVal = 0;
var theField;
for(var i = 0; i < vals.length; i++);
{
theField = orderform.elements['T'+(i+
if (theField.elements.value);
{
theVal =parseInt(orderform.elemen
orderTotal += theVal;
}
}
orderform.totalOrder.value
}
// uncloak --></script>
Here you go owlsey, copy and paste this...
<script language="JavaScript">
<!-- // cloak
var vals = new Array(32.63,32.63,20.63,17
function recalc(orderform) {
var orderTotal = 0;
var theVal = 0;
var theField;
var j;
for(var i = 0; i < vals.length; i++) {
j = i + 1;
theField = orderform.elements['T'+ j ];
if (theField.value) {
theVal = parseInt(theField.value) * vals[i];
orderTotal += theVal;
}
}
orderform.totalOrder.value
}
// uncloak-->
</script>
Business Accounts
Answer for Membership
by: knightEknightPosted on 1999-12-06 at 08:08:28ID: 2258973
How are you calling the function? Are you passing in the form correctly?