I wouldn't swear to it but I think that JavaScript 1.1 back in the 4.0 days
fields of the same name in a form created a collection under the form that
could be accessed like so:

for (i=0; i<= document.formname.subtotal.length; i++)
    {
    runningtotal += document.formname.subtotal[i].value
    }
   return runningtotal;

Obviously you will want to calculate the runningtotal, but hopefully that
will give an idea.

Bryan

----- Original Message -----
From: "Keith Purtell" <[EMAIL PROTECTED]>
To: "KCFusion" <[EMAIL PROTECTED]>
Sent: Thursday, May 17, 2001 4:37 PM
Subject: [KCFusion] Math JavaScript and CF output


> I have a project where employees will choose items from a company store.
> Each product on the page will have a description, price per item and
> subtotal. This is presented as a Web form, dynamically generated out of a
> product database. At the bottom of the page is a grand total and submit
> button. When you go to one item and enter your quantity (the only user
input
> field that is not readonly), an OnChange multiplies unit price times
> quantity to arrive at the subtotal, and also changes the grand total.
> Here's my problem. The JavaScript I'm using to add all the subtotals
> accommodates a fixed number of items. I don't know how to tell it to add
> every form field named "subtotal" or if that's even possible. Since each
> item is a table row inside CFOUTPUT, I can rig this to change each
subtotal
> field name to "subtotal_0", "subtotal_1", etc. But the JavaScript is at
the
> top of the page and loads before the server is finished outputting the
> company store items. Anyone ever attempted something like this?  Partial
> code enclosed.
>
>
> <HTML>
> <HEAD><TITLE>Ordering (VantageMed Company Store)</TITLE>
> <META Http-Equiv="Cache-Control" Content="no-cache">
> <META Http-Equiv="Pragma" Content="no-cache">
> <META Http-Equiv="Expires" Content="0">
> <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
> <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"><!--
> function cent(amount) {
> // returns the amount in the .99 format
>     return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10
> == Math.floor(amount*10)) ? amount + '0' : amount);
> }
>
> function update(form) {
>     var subtotal = (form.quantity.value - 0) * (form.unitcost.value - 0);
>     subtotal = Math.floor(subtotal * 100)/100;
>     form.subtotal.value = '$' + cent(subtotal);
>
>     var subtotal_0 = (form.quantity_0.value - 0) *
(form.unitcost_0.value -
> 0);
>     subtotal_0 = Math.floor(subtotal_0 * 100)/100;
>     form.subtotal_0.value = '$' + cent(subtotal_0);
>
>     total = subtotal + subtotal_0;
>     total = Math.floor(total * 100)/100;
>     form.total.value = '$' + cent(total);
> }
> //--></SCRIPT>
> </HEAD>
> <BODY bgcolor="WHITE" topmargin="5" leftmargin="10" marginheight="5"
> marginwidth="10"><DIV ALIGN="CENTER">
>
> <H2>Ordering</H2>
>
> <FORM ACTION="somewhere.cfm" METHOD="post">
> <TABLE BGCOLOR="gray" WIDTH="600" CELLSPACING="0" CELLPADDING="1"
> BORDER="0">
> <TR>
> <TD><TABLE WIDTH="598" CELLSPACING="1" CELLPADDING="2" BORDER="0">
> <TR BGCOLOR="white">
> <TD>name (product img link)</TD><TD COLSPAN="2">desc</TD>
> </TR>
> <TR BGCOLOR="white">
> <TD>size / color / style</TD><TD>quantity <INPUT TYPE="TEXT"
NAME="quantity"
> SIZE="4" onChange="update(this.form)"></TD><TD WIDTH="100" NOWRAP>ea
<INPUT
> TYPE="TEXT" NAME="unitcost" value="19.99" SIZE="6" READONLY></TD>
> </TR>
> <TR BGCOLOR="white">
> <TD> &nbsp;</TD><TD ALIGN="right">This item total &nbsp;&nbsp;</TD><TD
> NOWRAP>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE="TEXT" NAME="subtotal"
> SIZE="6" READONLY></TD>
> </TR>
> </TABLE>
> </TD></TR></TABLE><BR>
>
> <TABLE BGCOLOR="gray" WIDTH="600" CELLSPACING="0" CELLPADDING="1"
> BORDER="0">
> <TR>
> <TD><TABLE WIDTH="598" CELLSPACING="1" CELLPADDING="2" BORDER="0">
> <TR BGCOLOR="white">
> <TD>name (product img link)</TD><TD COLSPAN="2">desc</TD>
> </TR>
> <TR BGCOLOR="white">
> <TD>size / color / style</TD><TD>quantity <INPUT TYPE="TEXT"
> NAME="quantity_0" SIZE="4" onChange="update(this.form)"></TD><TD
WIDTH="100"
> NOWRAP>ea <INPUT TYPE="TEXT" NAME="unitcost_0" value="21.99" SIZE="6"
> READONLY></TD>
> </TR>
> <TR BGCOLOR="white">
> <TD> &nbsp;</TD><TD ALIGN="right">This item total &nbsp;&nbsp;</TD><TD
> NOWRAP>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE="TEXT" NAME="subtotal_0"
> SIZE="6" READONLY></TD>
> </TR>
> </TABLE>
> </TD></TR></TABLE><BR>
>
> <TABLE BGCOLOR="white" WIDTH="600" CELLSPACING="0" CELLPADDING="4"
> BORDER="0">
> <TR>
> <TD WIDTH="500" ALIGN="right">Grand total &nbsp;</TD>
> <TD WIDTH="100" NOWRAP>&nbsp;&nbsp;&nbsp;&nbsp;<INPUT TYPE="TEXT"
> NAME="total" SIZE="6" READONLY></TD>
> </TR>
> </TABLE>
> <BR>
>
> <TABLE WIDTH="600" CELLSPACING="0" CELLPADDING="4" BORDER="0">
> <TR>
> <TD ALIGN="center"><INPUT type="submit" NAME="send" value="Submit this
> catalog order"></TD>
> </TR>
> </TABLE>
> </FORM>
>
> <BR>
> </DIV>
> </BODY>
> </HTML>
>
>
> Keith Purtell, Web/Network Administrator
> VantageMed Operations (Kansas City)
>
> CONFIDENTIALITY NOTICE: This email message, including any attachments, is
> for the sole use of the intended recipient(s) and may contain confidential
> and privileged information. Any unauthorized review, use, disclosure or
> distribution is prohibited. If you are not the intended recipient, please
> contact the sender by reply email and destroy all copies of the original
> message.
>
>
>
> ______________________________________________________________________
> The KCFusion.org list and website is hosted by Humankind Systems, Inc.
> List Archives........ http://www.mail-archive.com/cf-list@kcfusion.org
> Questions, Comments or Glowing Praise.. mailto:[EMAIL PROTECTED]
> To Subscribe.................... mailto:[EMAIL PROTECTED]
> To Unsubscribe................ mailto:[EMAIL PROTECTED]
>
>

 
 
______________________________________________________________________
The KCFusion.org list and website is hosted by Humankind Systems, Inc.
List Archives........ http://www.mail-archive.com/cf-list@kcfusion.org
Questions, Comments or Glowing Praise.. mailto:[EMAIL PROTECTED]
To Subscribe.................... mailto:[EMAIL PROTECTED]
To Unsubscribe................ mailto:[EMAIL PROTECTED]
 

Reply via email to