Solved

Text field problem

Posted on 2003-10-22
16
167 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now