Solved

Text field problem

Posted on 2003-10-22
16
172 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
[X]
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
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

628 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