Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

Text field problem

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
AFLACK
Asked:
AFLACK
  • 9
  • 6
1 Solution
 
PluckaCommented:
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
 
hartCommented:
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
 
hartCommented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
hartCommented:
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
 
AFLACKAuthor Commented:
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
 
hartCommented:
:-)

yeah go through and let me know

regards
hart
0
 
AFLACKAuthor Commented:
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
 
hartCommented:
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
 
AFLACKAuthor Commented:
SORRY,

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

Thanks !!!
AF
0
 
AFLACKAuthor Commented:
When I get home ....
AF
0
 
AFLACKAuthor Commented:
Should be OK now ...
Sorry again,
AF
0
 
hartCommented:
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
 
hartCommented:
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
 
hartCommented:
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
 
AFLACKAuthor Commented:
hart,

Thanks a ton !! You helped me out of a jam --
Hope you enjoy(ed) your festival!
Thanks again,
AF
0
 
hartCommented:
yes i did njoy the festial
and u r always welcome :-)

Regards
Hart
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 9
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now