Javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xiou
    New Member
    • May 2009
    • 3

    Javascript

    I am new using javascript for the pdf and I have the following code and the calculation doesn't. What I am trying to do is if the person check USA it will display the correct value into the field otherwise if other than USA it will do the second case.
    Any help will be appreciated and thank you in advance.

    Here is what I have:

    Code:
    var AmtShipping = this.getField("Cost").value;
    var Country = this.getField("Country").value;
    
    if( AmtShipping == 0)
    event.value = '';
    if(( AmtShipping == 7)&&(Country ==USA))
       event.value = 9.00;
    if((AmtShipping ==9)&&( Country ==USA))
            event.value = 4.50;
    if((AmtShipping <=50)&&( Country ==USA))
            event.value = 9.00;
    if((AmtShipping <=100)&&( Country ==USA))
            event.value = 12.00;
    if((AmtShipping <=150)&&( Country ==USA))
            event.value = 12.00;
    if( AmtShipping >= 151)
    {
         event.value = 25.00};
    if((AmtShipping <=50)&&( Country !=USA))
    event.value = 18.00;
    if((AmtShipping <=100)&&( Country !=USA))
    event.value = 22.00;
    if((AmtShipping <=150)&&( Country !=USA))
    event.value = 27.00;
    if( AmtShipping >= 151)
    {
         event.value = 32.00};

    Thank you in advance
    Last edited by Niheel; Aug 4 '10, 04:11 PM.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    from the language point-of-view, USA should be quoted, using filling zeroes is pointless, JS has exactly 1 number type (IEEE 754 float).

    you *may* run into trouble using event as variable name.

    And I’d definitely split the conditions, so that you don’t have to check 2 conditions at once.
    Code:
    // needs to be put in a function
    if ("USA" == Country) {
        if (AmtShipping <= 50) {
            return 9;
        }
        if (AmtShipping <= 100) {
            return 12;
        }
        // etc.
    }
    else {
        // …
    }

    Comment

    • xiou
      New Member
      • May 2009
      • 3

      #3
      Thank you so much for your help.

      Comment

      Working...