Copy link to clipboard
Copied
I am unfamilar with JavaScript and need to create a calculation for a PDF form. The form is used to determine profit. There is a radio button called payroll with two values, "internal" and "external". One calculation to determine costs will need to say: if payroll equals "internal" then 1.02 else .98. This number will then insert in the costs field. The other calculation to determine markup will need to say: if payroll equals "internal" then 1.2 else 1.4. Thanks in advance for the assistance.
Copy link to clipboard
Copied
Costs field calculate event:
if (this.getField("payroll").value == 'internal') {
event.value = 1.02
} else {
event.value = .98
}
Copy link to clipboard
Copied
Costs field calculate event:
if (this.getField("payroll").value == 'internal') {
event.value = 1.02
} else {
event.value = .98
}
Copy link to clipboard
Copied
Thank you so much. I was then able to answer the second part of the question using the formula you provided. Again, thank you.
Copy link to clipboard
Copied
You're welcome.
Note that this makes 'External' the 'default' value for the field (e.g. - if anything other than Internal is entered, it will default to .98)
If you want 'Internal to be the 'default', then change the order of the If/else statements, and change the IF to this.getField("payroll").value == 'external'
If you want a blank default (or other value) if something other than 'internal' or 'external' is entered, then you can use the following:
if (this.getField("payroll").value == 'internal') {
event.value = 1.02
} else if (this.getField("payroll").value == 'external') {
event.value = .98
} else {
event.value = 0 // Default value here
}
Copy link to clipboard
Copied
Thanks for the information. How would you write it if you wanted to set up the same criteria but have the event.value multiply the 1.02 or .98 times the pay rate field?
Copy link to clipboard
Copied
I have a similar problem with the following Syntax Error: "identifier start starts immediately after numeric literal".
Where is my mistake? Unfortunately, I am not familiar with Java.
(Ramp shall be a dropdown list where I can select different locations. If in the dropdown list the PLACE1 is selected the article number shall be shown.)
Thank you for your support and advice!
if(this.getField("Ramp").value=="PLACE1"){
this.getField("Apple").value= "11082";
}
else if(this.getField("Ramp").value=="PLACE2") {
this.getField("Apple").value="11081";
}
else if(this.getField("Ramp").value=="PLACE3"){
this.getField("Apple").value="11083";
}
else {
this.getField("Apple").value="select Ramp";
}
Copy link to clipboard
Copied
This code is fine. As mentioned, you might be placing it in the wrong location.
Copy link to clipboard
Copied
HI,
Can I check where the code is placed in the PDF file? The error looks like you are placing JavaScript in a "Simplified field notation" field where as it needs to be in the "Custom calculation script".
Regards
Malcolm
Copy link to clipboard
Copied
Thank you for your advices. I already put this in "Custom Calculation script" and I got the syntax error...
What else might be wrong?
Copy link to clipboard
Copied
HI,
Can you share the file, using dropbox or similar, as stated the code you have posted looks fine.
Regards
Malcolm