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.
Views
Replies
Total Likes
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
Thanks for your quick reply. Below is the exact code that I have put in:
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.
Views
Replies
Total Likes
You are missing a colon after "Semi-Monthly" and "Monthly".
Steve
Thank you for catching that. It still is not calculating the annual payment using the corrected code.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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?
Views
Replies
Total Likes
Yes. Please forward the form to stwalker.adobe@gmail.com and I can take a look.
Steve
Views
Replies
Total Likes
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;
}
}
}
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies