Thanks Brian!

-----Original Message-----
From: Brian Scandale [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 23, 2002 1:36 PM
To: CF-Talk
Subject: RE: OT javascript addition


Tim,

Below is a cut and paste of some javascript that I use to process numeric
fields and push calculated results into other fields on the page. It's
pretty well documented so that you can see what and how it does it... You
can easily modify it to do whatever math you might need. Notice how it loops
over the fields in the form... collecting the values and finally calculating
new results with the values it collected... it even changes the colors on
some of the result fields if so desired. 

Hope this helps.


---- begin javascript cut and paste ----
<!-- incINVscript -->
<!--- SCRIPT USED TO CALCULATE GOOD AND REJECTS AND COUNT REJECTS ETC ON
CHECKOUT --->
<!--- BEGIN CFHTMLHEAD --->
<cfhtmlhead text='
<script language="JavaScript" type="text/javascript">
<!--
function CalculateTotal(frm) {
    var sum_rej = 0
        var good = 0
        var rework = 0
        var cur_inv = 0
        var start_qty = 0
        var good_inv = 0
        var rework_qty = 0
        var reworkis = 0
        // Run through all the form fields to calc rejs accounted for
    for (var i=0; i < frm.elements.length; ++i) {
                // Get the current field
        form_field = frm.elements[i];
        // Get the field"s name
        form_name = form_field.name;
        // Is it a "reject" field?
        if (form_name.substring(0,4) == "REJX") {
            // Get the quantity
            rej_qty = parseInt(form_field.value)
            // Update the order total


                        if (rej_qty > -999999999) {
                                form_field.value = rej_qty ;
                        }
                        else {
                                form_field.value = "" ;
                        }
            if (rej_qty < 0) {
                form_field.value = "" ;
            }

            if (rej_qty >= 0) {
                sum_rej += rej_qty
            }

        }
                if (form_name.substring(0,3) == "Inv") {
            cur_inv = parseInt(form_field.value)
        }
                if (form_name.substring(0,8) == "StartQty") {
            start_qty = parseInt(form_field.value)
        }
                if (form_name.substring(0,4) == "Good") {
            good_inv = parseInt(form_field.value)
        }
                if (form_name.substring(0,6) == "Rework") {
            rework_qty = parseInt(form_field.value);
                        reworkis = 1;
        }
    }

    // Display the total rejects accounted for
    frm.TotalRej.value = sum_rej;
        
        // Display the rejects needed
        totalrejneeded = cur_inv - good_inv;
    frm.TotalRejNeeded.value = totalrejneeded   ;

        if (reworkis == 1){
                totalrpt = good_inv + rework_qty;
        }
        if(sum_rej > totalrejneeded){
                frm.TotalRejNeeded.style.backgroundColor = "red";
                frm.TotalRejNeeded.style.color = "white";
        }
        else {
                frm.TotalRejNeeded.style.backgroundColor = "white";
                frm.TotalRejNeeded.style.color = "black";
        }
        if(good_inv > start_qty){
                frm.Good.style.backgroundColor = "red";
                frm.Good.style.color = "white";
        }
        else {
                frm.Good.style.backgroundColor = "white";
                frm.Good.style.color = "black";
        }
        
        if (reworkis == 1){
                if(totalrpt > start_qty){
                        frm.Good.style.backgroundColor = "red";
                        frm.Good.style.color = "white";
                        frm.Rework.style.backgroundColor = "red";
                        frm.Rework.style.color = "white";
                }
                else {
                        frm.Good.style.backgroundColor = "white";
                        frm.Good.style.color = "black";
                        frm.Rework.style.backgroundColor = "white";
                        frm.Rework.style.color = "black";
                }
        }
}
//-->
</script>
'>
<!--- END CFHTMLHEAD --->

---- end cut and paste ----


At 12:45 PM 7/23/02, you wrote:
>Hi Brook,
>this is what I'm using but getting "expecting )" error... please help =)
>
>function validate()
>{
>        var sumValue =
>eval(document.newBillingInfo.SCEPbilledAmount.value.valueOf()) +
>eval(document newBillingInfo.SCEPpenaltyAmount.value.valueOf()) +
>eval(document newBillingInfo.SCEPdelinquentAmount.value.valueOf())
>
>        var total =  eval("document.newBillingInfo.SCEPtotalAmount.value")
>        if (sumValue != total)
>        {
>        alert(sumValue)
>        document.newBillingInfo.SCEPbilledAmount.focus()
>        return false;
>        }       
>        
>        return true;
>        
>}
>
>-----Original Message-----
>From: Brook Davies [mailto:[EMAIL PROTECTED]]
>Sent: Tuesday, July 23, 2002 12:38 PM
>To: CF-Talk
>Subject: RE: OT javascript addition
>
>
>I had the same problem the other day. This works FOR SURE:
>
>eval(document.newBillingInfo.SCEPbilledAmount.value.valueOf())+eval(documen
t
>
>newBillingInfo.SCEPpenaltyAmount.value.valueOf())
>
>Using the valueOf() function converts a string to a number.
>
>Brook Davies
>maracasmedia.com
>
>
>
>At 12:13 PM 23/07/02 -0700, you wrote:
>>Try doing eval(document.newBillingInfo.SCEPbilledAmount.value) +
>>eval(document.newBillIngo.SCEPpenaltyAmount.value), etc.  At least in
>>ActionScript (Flash) this forces the value to be treated as a number for
>>addition purposes.  A quick test in IE javascript showed it to work there
>>also.
>>
>>Dan
>>
>>-----Original Message-----
>>From: Tim Do [mailto:[EMAIL PROTECTED]]
>>Sent: Tuesday, July 23, 2002 11:30 AM
>>To: CF-Talk
>>Subject: RE: OT javascript addition
>>
>>
>>Thanks Stephen.. I tried that earlier but that only concatenates it
>>
>>-----Original Message-----
>>From: Stephen Kellogg [mailto:[EMAIL PROTECTED]]
>>Sent: Tuesday, July 23, 2002 10:08 AM
>>To: CF-Talk
>>Subject: RE: OT javascript addition
>>
>>
>>Tim,
>>try adding () around the addition part like so:
>>
>>if ((document.newBillingInfo.SCEPbilledAmount.value +
>>document.newBillingInfo.SCEPpenaltyAmount.value +
>>document.newBillingInfo.SCEPdelinquentAmount.value) !=
>>document.newBillingInfo.SCEPtotalAmount.value)
>>
>>
>>This should force the addition to take place before the comparison.
>>
>>PS are you checking for numeric input only
>>
>>This could be done like so:
>>
>>if ((isNaN(document.newBillingInfo.SCEPbilledAmount.value)) ||
>>(isNaN(document.newBillingInfo.SCEPpenaltyAmount.value))  ||
>>(isNaN(document.newBillingInfo.SCEPdelinquentAmount.value))  ||
>>(isNaN(document.newBillingInfo.SCEPtotalAmount.value))
>>         {
>>         alert("The amounts must be numeric, Please
>>check the values.")
>>         document.newBillingInfo.SCEPbilledAmount.focus()
>>         return false;
>>         }
>>else
>>         {
>>if ((document.newBillingInfo.SCEPbilledAmount.value +
>>document.newBillingInfo.SCEPpenaltyAmount.value +
>>document.newBillingInfo.SCEPdelinquentAmount.value) !=
>>document.newBillingInfo.SCEPtotalAmount.value)
>>         {
>>         alert("The total Billing amount does not add up correctly, Please
>>check the values.")
>>         document.newBillingInfo.SCEPbilledAmount.focus()
>>         return false;
>>         }
>>
>>         return true;
>>         }
>>}
>>
>>
>>or something like that ;-)
>>
>>this is untested code but hopefully will give you something to work with.
>>
>>HTH
>>
>>Stephen
>>
>>-----Original Message-----
>>From: Tim Do [mailto:[EMAIL PROTECTED]]
>>Sent: Tuesday, July 23, 2002 12:36 PM
>>To: CF-Talk
>>Subject: javascript addition
>>
>>
>>Hello,
>>
>>Can anybody show me how you would I would validate the sum of several text
>>boxes?  This is what I'm trying to use but not having luck.. thanks in
>>advance.
>>
>>function validate()
>>{
>>  if (document.newBillingInfo.SCEPbilledAmount.value +
>>document.newBillingInfo.SCEPpenaltyAmount.value +
>>document.newBillingInfo.SCEPdelinquentAmount.value !=
>>document.newBillingInfo.SCEPtotalAmount.value)
>>         {
>>         alert("The total Billing amount does not add up correctly, Please
>>check the values.")
>>         document.newBillingInfo.SCEPbilledAmount.focus()
>>         return false;
>>         }
>>
>>         return true;
>>
>>}
>>
>>
>>
>>
>
>

______________________________________________________________________
This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to