|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
OT javascript addition
Author: Tim Do
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:14272#73927
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 -----
Author: Brian Scandale
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:14272#73921
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 -----
Author: Matthew R. Small
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:14272#73914
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;
}
Author: Stephen Kellogg
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:14272#73911
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;
}
Author: Tangorre, Michael
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:14272#73910
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 -----
Author: Tim Do
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:14272#73908
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 -----
Author: Chris Lofback
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:14272#73907
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 -----
Author: Brook Davies
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:14272#73905
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 -----
Author: Shawn Grover
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:14272#73900
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;
}
Author: Shawn Grover
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:14272#73898
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;
}
Author: ksuh
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:14272#73897
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 -----
Author: Dan Haley
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:14272#73895
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;
}
Author: Tim Do
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:14272#73887
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;
}
Author: Stephen Kellogg
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:14272#73865
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;
}
|
May 24, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||