Solved

Text field problem

Posted on 2003-10-22
16
168 Views
Last Modified: 2013-12-24
Not sure if this should be in javascript area or CF area but here is my problem.
I have a form that works except for this one problem. If you click in a text box beside a select box that a retailer has not been selected and then click out of it it says "NaN" and screws up my total field also with a "NaN".
The form is here - http://www.stpaulsalem.dynu.com/tip/orderform.cfm
And to save on posting space, the code is in a zip file here - http://www.stpaulsalem.dynu.com/orderform.zip

I want the person to be able to click in the qty field of a row that does not have a retailer selected yet and it not to say NaN but just remain Null (blank) until there is a retailer selected beside it. Or if I can disable (readonly) the qty text boxes until a retailer is entered that would be OK also.
Hope I explained myself OK , if not I can reword it if needed.

Thanks in advance,
AF
0
Comment
Question by:AFLACK
  • 9
  • 6
16 Comments
 
LVL 18

Expert Comment

by:Plucka
ID: 9604397
It's a problem with the Javascript function.

         function Calculate_Totals(Sent_ID)
          {
               var d = document.tipOrderForm
               var I = 1;
               Running_ID = Get_ID(Sent_ID);
               UpDateTextBoxes("retailer" + Running_ID);

               d("qty" + Running_ID).value = Math.abs(d("qty" + Running_ID).value);
               d("subtotal" + Running_ID).value = Running_Amount * d("qty" + Running_ID).value;
               d("subrebate" + Running_ID).value = Running_Amount * d("qty" + Running_ID).value * (1 * Running_Percentage);
               d("grandrebate").value = 0;
               d("grandtotal").value = 0;

               for (I=1;I<=12;I++)
               {
                    d("grandtotal").value = (d("grandtotal").value * 1) + (d("subtotal" + I).value * 1);
                         d("grandrebate").value = (d("grandrebate").value * 1) + (d("subrebate" + I).value * 1);
               }
               return true;
          }
     </script>

You just need to check if the value is 0 or not ie:

if (d("qty" + Running_ID).value == '0') {
    d("subtotal" + Running_ID).value = '0';
}
else {
    d("subtotal" + Running_ID).value = Running_Amount * d("qty" + Running_ID).value;
}
0
 
LVL 11

Accepted Solution

by:
hart earned 65 total points
ID: 9604460
try this out

change ur existing UpDateTextBoxes(Sent_ID) javascript function with the below one and  let me know if its right


function UpDateTextBoxes(Sent_ID)
          {
               var d = document.tipOrderForm(Sent_ID);
               var d2 = document.tipOrderForm;
               
               Running_ID            = Get_ID(Sent_ID);
               Text                  = d.options[d.options.selectedIndex].text;
                     if(d.options[d.options.selectedIndex].value != '')
                     {
                              Money_Start           = Text.indexOf("$")+1;
                              Money_End             = Text.indexOf(" ",Money_Start);
                              Percent_Start         = Text.indexOf("with a ") + 7;
                              Percent_End           = Text.indexOf("%");
                              
                              Running_Percentage    = Text.substring(Percent_Start, Percent_End) / 100;
                              Running_Amount        = Text.substring(Money_Start,Money_End) * 1;
                              
                              Rebate_ID               = "rebate" + Running_ID;
                              Denom_ID               = "denom" + Running_ID;
                              
                              d2(Rebate_ID).value     = Running_Percentage;
                              d2(Denom_ID).value     = Running_Amount;
                        }
                        else
                        {
                              Running_Percentage            = 0;
                              Running_Amount                  = 0;
                              Rebate_ID               = "rebate" + Running_ID;
                           Denom_ID                     = "denom" + Running_ID;
         
                           d2(Rebate_ID).value     = 0;
                           d2(Denom_ID).value           = 0;
                        }

               return true;
          }

but don't mind but 30 pts is kind of less for going through all ur stuff :-)
just kidding ok...

Regards
Hart
0
 
LVL 11

Expert Comment

by:hart
ID: 9604481
there are lot of checks that can be put in
like u could check wether the select box value is the first one and if the user enters quantity then alert him to select the retailer first.

also when the drop down is changed update the quatity to 0..

small small checks like that can be put in :-)

Regards
Hart
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 11

Expert Comment

by:hart
ID: 9604525
plucka this check won't do it

if (d("qty" + Running_ID).value == '0') {
   d("subtotal" + Running_ID).value = '0';
}
else {
   d("subtotal" + Running_ID).value = Running_Amount * d("qty" + Running_ID).value;
}

because even if say d("qty" + Running_ID).value != '0' but the selected item of the drop down box is the first one it will give NAN..

because he is getting the amounts from the drop down option text.
and running_amount gets formed from there

Regards
Hart
0
 

Author Comment

by:AFLACK
ID: 9605895
i am going over all your stuff - I will get to it later today. I also uped the point i meant to put it a 60 not 30 sorry...(ahh.. i will put it at 65 just for fun...)

0
 
LVL 11

Expert Comment

by:hart
ID: 9605928
:-)

yeah go through and let me know

regards
hart
0
 

Author Comment

by:AFLACK
ID: 9611412
Hart,
Thanks  a ton...
It makes the field show up as a zero, which works... but how difficult would it be to make it blank unless there is something chosen in the retailer field next to it?

AF
0
 
LVL 11

Expert Comment

by:hart
ID: 9612186
it won't be that difficult :-)

but the problem is i can't go to the http://www.stpaulsalem.dynu.com/tip/orderform.cfm
directly it asks for a login/pass

i can use ur code zip as it has got queries and i don't have the time to create tables and check.

could u open the link to http://www.stpaulsalem.dynu.com/tip/orderform.cfm
directly so that i can take a view source of the page and put the checks and give..

Regards
Hart
0
 

Author Comment

by:AFLACK
ID: 9615992
SORRY,

I was messing with the login for that, I will remove the application.cfm so you can get in.

Thanks !!!
AF
0
 

Author Comment

by:AFLACK
ID: 9616000
When I get home ....
AF
0
 

Author Comment

by:AFLACK
ID: 9617731
Should be OK now ...
Sorry again,
AF
0
 
LVL 11

Expert Comment

by:hart
ID: 9624866
sorry it was festival time out here.
the thing is i am from indai, and it was iwali festival out here, so couldn't check ur link will post as soon as i get the view sorce :-)

Regards
Hart
0
 
LVL 11

Expert Comment

by:hart
ID: 9625119
use this function

function UpDateTextBoxes(Sent_ID)
          {
               var d = document.tipOrderForm(Sent_ID);
               var d2 = document.tipOrderForm;
               
               Running_ID            = Get_ID(Sent_ID);
               Text                  = d.options[d.options.selectedIndex].text;
               if(d.options[d.options.selectedIndex].value != '')
               {
                      Money_Start           = Text.indexOf("$")+1;
                      Money_End             = Text.indexOf(" ",Money_Start);
                      Percent_Start         = Text.indexOf("with a ") + 7;
                      Percent_End           = Text.indexOf("%");
                     
                      Running_Percentage    = Text.substring(Percent_Start, Percent_End) / 100;
                      Running_Amount        = Text.substring(Money_Start,Money_End) * 1;
                     
                      Rebate_ID               = "rebate" + Running_ID;
                      Denom_ID               = "denom" + Running_ID;
                     
                      d2(Rebate_ID).value     = Running_Percentage;
                      d2(Denom_ID).value     = Running_Amount;
                 }
                 else
                 {
                      Running_Percentage          = 0;
                      Running_Amount              = 0;
                      Rebate_ID                       = "rebate" + Running_ID;
                      Denom_ID                    = "denom" + Running_ID;
       
                      d2(Rebate_ID).value             = 0;
                      d2(Denom_ID).value          = 0;
                                
                 }
                         
               return true;
          }


and in ur select boxes

<select name="retailer1" id="retailer1"  onChange="Calculate_Totals(this.id)">

change the onChange event to Calculate_Totals(this.id) instead of UpDateTextBoxes(this.id);

so even if the user selects choose a retailer after choosing soething the values will get changed to 0...

i did not make it null, other wise  i will have to change ur functions a lot..

Regards
Hart
0
 
LVL 11

Expert Comment

by:hart
ID: 9625127
sorry i left out this change ur  Calculate_Totals(Sent_ID) to the below one


function Calculate_Totals(Sent_ID)
          {
               var d = document.tipOrderForm
               var I = 1;
               Running_ID = Get_ID(Sent_ID);
               UpDateTextBoxes("retailer" + Running_ID);
               if(Running_Amount != 0)
                     {
                           d("qty" + Running_ID).value = Math.abs(d("qty" + Running_ID).value);
                     }
                     else
                     {
                      d("qty" + Running_ID).value = 0;
                     }
               d("subtotal" + Running_ID).value = Running_Amount * d("qty" + Running_ID).value;
               d("subrebate" + Running_ID).value = Running_Amount * d("qty" + Running_ID).value * (1 * Running_Percentage);
               d("grandrebate").value = 0;
               d("grandtotal").value = 0;

               for (I=1;I<=12;I++)
               {
                    d("grandtotal").value = (d("grandtotal").value * 1) + (d("subtotal" + I).value * 1);
                         d("grandrebate").value = (d("grandrebate").value * 1) + (d("subrebate" + I).value * 1);
               }
               return true;
          }

Regards
hart
0
 

Author Comment

by:AFLACK
ID: 9631118
hart,

Thanks a ton !! You helped me out of a jam --
Hope you enjoy(ed) your festival!
Thanks again,
AF
0
 
LVL 11

Expert Comment

by:hart
ID: 9631464
yes i did njoy the festial
and u r always welcome :-)

Regards
Hart
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Running Guacamole on port 80 5 212
Reverse Proxy Server 6 82
How to stress test an ASP.NET https website 3 71
move expression web site to a new server 12 30
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question