House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

OT javascript addition

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Tim,
Stephen Kellogg
07/23/02 01:23 P
sorry
Stephen Kellogg
07/23/02 03:49 P
Hi Brook,
Tim Do
07/23/02 03:43 P
semicolons, semicolons :-)
Tangorre, Michael
07/23/02 03:45 P
Tim,
Brian Scandale
07/23/02 04:37 P
Thanks Brian!
Tim Do
07/23/02 05:06 P
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Stephen Kellogg
07/23/2002 01:23 PM

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 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; }

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Tim Do
07/23/2002 03:07 PM

Thanks Stephen.. I tried that earlier but that only concatenates it 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 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; }

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Stephen Kellogg
07/23/2002 03:49 PM

sorry try this: if ((eval(document.newBillingInfo.SCEPbilledAmount.value)) + (eval(document.newBillingInfo.SCEPpenaltyAmount.value)) + (eval(document.newBillingInfo.SCEPdelinquentAmount.value))) != document.newBillingInfo.SCEPtotalAmount.value) SK Thanks Stephen.. I tried that earlier but that only concatenates it 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 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; }

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Matthew R. Small
07/23/2002 04:00 PM

Wow, that's correct but it sure does have a lot of parentheses. Shouldn't the order of precedence be enough to get the addition correct? sorry try this: if ((eval(document.newBillingInfo.SCEPbilledAmount.value)) + (eval(document.newBillingInfo.SCEPpenaltyAmount.value)) + (eval(document.newBillingInfo.SCEPdelinquentAmount.value))) != document.newBillingInfo.SCEPtotalAmount.value) SK Thanks Stephen.. I tried that earlier but that only concatenates it 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 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; }

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dan Haley
07/23/2002 03:16 PM

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 Thanks Stephen.. I tried that earlier but that only concatenates it 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 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; }

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Brook Davies
07/23/2002 03:27 PM

I had the same problem the other day. This works FOR SURE: eval(document.newBillingInfo.SCEPbilledAmount.value.valueOf())+eval(document .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: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
ksuh
07/23/2002 03:18 PM

You'll have to use parseFloat or parseInt to explicitly cast the value to a number.  Then you'll be able to add them. However, a BIG word of warning:  JavaScript SUCKS at proper floating point manipulation. There are functions that you can find that'll clear up the numbers before you add them that can help, or if you're in using IE only, use VBScript instead. ----- Excess quoted text cut - see Original Post for more ----- Please ----- Excess quoted text cut - see Original Post for more ----- Please ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Shawn Grover
07/23/2002 03:22 PM

If that's the case, add a parseInt() or parseFloat() around each variable to make sure it is in fact a numeric value.  Or you may have to do some validation first (i.e. can the user enter "HELLO" for a numeric value?). Also on this note, you might have to strip any formatting (i.e. "$1,000.00" and "1,000.00" will not be interpreted as a number by javascript - the comma and dollar sign need to be stripped). HTH. Shawn Grover Thanks Stephen.. I tried that earlier but that only concatenates it 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 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; }

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Shawn Grover
07/23/2002 03:25 PM

but keep in mind that eval() is a little slower in processing time bacause you are first converting a string value, then interpreting it. While I know it's needed quite often, I would try to avoid the use of eval() whenever possible - especially if you are dealing with numeric values. Also, in this case if your numbers are formatted, then eval() will end up raising an error. My thoughts. Shawn Grover 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 Thanks Stephen.. I tried that earlier but that only concatenates it 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 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; }

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Chris Lofback
07/23/2002 03:37 PM

Another workaround is using the old "subtract zero" trick: if ((document.newBillingInfo.SCEPbilledAmount.value-0) + (document.newBillingInfo.SCEPpenaltyAmount.value-0) + (document.newBillingInfo.SCEPdelinquentAmount.value-0) != (document.newBillingInfo.SCEPtotalAmount.value-0)) This forces JavaScript to recast the values as numbers. Chris Lofback Sr. Web Developer TRX Integration 28051 US 19 N., Ste. C Clearwater, FL  33761 www.trxi.com I had the same problem the other day. This works FOR SURE: eval(document.newBillingInfo.SCEPbilledAmount.value.valueOf())+eval(document 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: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Tim Do
07/23/2002 03:43 PM

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;    } I had the same problem the other day. This works FOR SURE: eval(document.newBillingInfo.SCEPbilledAmount.value.valueOf())+eval(document 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: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Tangorre, Michael
07/23/2002 03:45 PM

semicolons, semicolons  :-) 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;    } I had the same problem the other day. This works FOR SURE: eval(document.newBillingInfo.SCEPbilledAmount.value.valueOf())+eval(document 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: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Brian Scandale
07/23/2002 04:37 PM

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: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Tim Do
07/23/2002 05:06 PM

Thanks Brian! 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: ----- Excess quoted text cut - see Original Post for more ----- t ----- Excess quoted text cut - see Original Post for more -----


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

March 22, 2010

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
   1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31