• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
1

If Else Statement for PDF Form

Community Beginner ,
Jun 10, 2010 Jun 10, 2010

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.

Views

22.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Jun 10, 2010 Jun 10, 2010

Costs field calculate event:

if (this.getField("payroll").value == 'internal') {
event.value = 1.02
} else {
event.value = .98
}

Votes

Translate

Translate
Advocate ,
Jun 10, 2010 Jun 10, 2010

Copy link to clipboard

Copied

Costs field calculate event:

if (this.getField("payroll").value == 'internal') {
event.value = 1.02
} else {
event.value = .98
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 11, 2010 Jun 11, 2010

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 11, 2010 Jun 11, 2010

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
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 11, 2010 Jun 11, 2010

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? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 20, 2018 Jun 20, 2018

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";

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 20, 2018 Jun 20, 2018

Copy link to clipboard

Copied

This code is fine. As mentioned, you might be placing it in the wrong location.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 20, 2018 Jun 20, 2018

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 20, 2018 Jun 20, 2018

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 20, 2018 Jun 20, 2018

Copy link to clipboard

Copied

LATEST

HI,

Can you share the file, using dropbox or similar, as stated the code you have posted looks fine.

Regards

Malcolm

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines