8 Replies Latest reply on Sep 28, 2010 8:50 AM by csmaughanSLC

    Calculating numbers from text values

    csmaughanSLC

      Hello,

       

      I am trying to get a form that will calculate the annual salary of an individual from a paycheck amount.  I have three fields: "paycheckAmount", "paymentFrequency", and "annualIncome".  The paycheckAmount field is set to be a number field.  The paymentFrequency field is a dropdown menu that give the options "Weekly", "Bi-Weekly", "Semi-Monthly", "Monthly", and "Annual".  Is there a way to have the form automatically calculate the annual income based on the input of the paymentFrequency and paycheckAmount fields?

       

      Thank you in advance for help with this.

        • 1. Re: Calculating numbers from text values
          mustafa41

          DropDownList2 is your income frequency, numericfield4 is your annualIncome and numericField3 is your checkAmount. Make sure that the following script is located on your annualIncome.

          form1.#subform[0].NumericField4::calculate - (JavaScript, client)
          switch(DropDownList2.rawValue){
            case "Weekly":
                this.rawValue=NumericField3.rawValue*52;
                break;
            case "Bi-weekly":
                this.rawValue=NumericField3.rawValue*26;
                break;
            case "Monthly":
                this.rawValue=NumericField3.rawValue*12;
                break;
            case "Annual":
                this.rawValue=NumericField3.rawValue;
                break;
            default:
                this.rawValue=0;
                }

           

           

          MC

          1 person found this helpful
          • 2. Re: Calculating numbers from text values
            csmaughanSLC Level 1

            Thanks for your quick reply.  Below is the exact code that I have put in:

             

            form1.#subform[0].Table1.Row4.applicantAnnualIncome::calculate - (JavaScript, client)
            switch(ApplicantFrequency.rawValue){
                case "Weekly":
                    this.rawValue=ApplicantIncome.rawValue*52;
                    break;
                case "Bi-Weekly":
                    this.rawValue=ApplicantIncome.rawValue*26;
                    break;
                case "Semi-Monthly"
                    this.rawValue=ApplicantIncome.rawValue*24;
                    break;
                case "Monthly"
                    this.rawValue=ApplicantIncome.rawValue*12;
                    break;
                case "Annual":
                    this.rawValue=ApplicantIncome.rawValue;
                    break;
            }

            It is giving me an error on line 10, although I don't know what the problem is.  Also, it is not working when I test the form.

            • 3. Re: Calculating numbers from text values
              Steve L Walker Level 5

              You are missing a colon after "Semi-Monthly" and "Monthly".

               

              Steve

              1 person found this helpful
              • 4. Re: Calculating numbers from text values
                csmaughanSLC Level 1

                Thank you for catching that.  It still is not calculating the annual payment using the corrected code.


                • 5. Re: Calculating numbers from text values
                  Steve L Walker Level 5

                  Using text fields for numbers makes me a bit squeamish so I tend to check for numbers (isNaN) and convert strings to integers (parseInt) or floats (parseFloat) depending upon the requirements. The following code produces an integer annual income.

                   

                  // form1.page1.applicantAnnualIncome::calculate - (JavaScript, client)


                  if (!(form1.page1.ApplicantIncome.isNull)) {

                    var incomeStr = ApplicantIncome.rawValue;

                    if (isNaN(incomeStr)) {

                      xfa.host.messageBox("Income is not a number.","Income Validation",1);

                      this.rawValue = null;

                    }

                    else {

                      var incomeInt = parseInt(incomeStr);

                      switch (ApplicantFrequency.rawValue) {

                        case "Weekly":

                          this.rawValue = incomeInt * 52;

                          break;

                        case "Bi-Weekly":

                          this.rawValue = incomeInt * 26;

                          break;

                        case "Semi-Monthly":

                          this.rawValue = incomeInt * 24;

                          break;

                        case "Monthly":

                          this.rawValue = incomeInt * 12;

                          break;

                        case "Annual":

                          this.rawValue = incomeInt;

                          break;

                        default:

                          break;

                      }

                    }

                  }

                   

                  Steve

                  • 6. Re: Calculating numbers from text values
                    csmaughanSLC Level 1

                    Thank you very much for your help.  I am still having issues getting that code to work.  I have downloaded the file you provided, and compared the files.  The only difference is that my data is held in a table.  Would that make a difference?

                    • 7. Re: Calculating numbers from text values
                      Steve L Walker Level 5

                      Yes. Please forward the form to stwalker.adobe@gmail.com and I can take a look.

                       

                      Steve

                      • 8. Re: Calculating numbers from text values
                        csmaughanSLC Level 1

                        The following code was used within the table:

                         

                         

                        if (!(xfa.resolveNode("form1.page1.income.table.row[0].applicantIncome").isNull)) {
                            var income = xfa.resolveNode("form1.page1.income.table.row[0].applicantIncome").rawValue;
                            if (isNaN(income)) {
                                xfa.host.messageBox("The applicant income is not a number.","Income Validation",1);
                                this.rawValue = null;
                            }
                            else {
                                var freq = xfa.resolveNode("form1.page1.income.table.row[1].applicantIncomeFreq").rawValue;
                                switch (freq) {
                                    case "Weekly":
                                        this.rawValue = income * 52;
                                        break;
                                    case "Bi-Weekly":
                                        this.rawValue = income * 26;
                                        break;
                                    case "Semi-Monthly":
                                        this.rawValue = income * 24;
                                        break;
                                    case "Monthly":
                                        this.rawValue = income * 12;
                                        break;
                                    case "Annual":
                                        this.rawValue = income;
                                        break;
                                    default:
                                        break;
                                }
                            }
                        }