Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Text field problem

Posted on 2003-10-22
16
169 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

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

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

839 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