Skip to main content
dadocdahawaii
Participant
August 31, 2018
Answered

If else not working

  • August 31, 2018
  • 1 reply
  • 2285 views

Hi

I spent a lot of time reading and talking with folks.  Finally wrote the script properly

Adobe said no problems but it still doesn't work.

[side question: javascript developer was unsure about event.value and this.getfield.  These are defined by Acrobat?)

Have drop down field with 3 results: Pass, Fail or NA

IF Pass then print averagesupplyrows

If Fail then print averagesupplyrowsleft

IF NA then print NA

see script:

var nSupplyvelocitypassfailnaDD = this.getfield("SupplyvelocitypassfailnaDD").value;

var nAveragesupplyrows = this.getfield("averagesupplyrows").value;

var nAveragesupplyrowsleft = this.getfield("averagesupplyrowslefta").value;

if( SupplyvelocitypassfailnaDD == "Pass" ) {

event.value = nAveragesupplyrows;

}

else if( SupplyvelocitypassfailnaDD == "Fail" ) {

event.value = nAveragesupplyrowslefta;

}

else if ( SupplyvelocitypassfailnaDD == "NA" ) {

event.value = "NA";

}

This topic has been closed for replies.
Correct answer Test Screen Name

The first thing is to check the JavaScript console. Error messages don't pop up, instead they all go in the console. Anything there?

If not, please tell us exactly where you put the script. Each field has many different events, and it's easy to put things in the wrong place.

1 reply

Test Screen NameCorrect answer
Legend
August 31, 2018

The first thing is to check the JavaScript console. Error messages don't pop up, instead they all go in the console. Anything there?

If not, please tell us exactly where you put the script. Each field has many different events, and it's easy to put things in the wrong place.

dadocdahawaii
Participant
August 31, 2018

Thank you.

I got the console open, no errors that I can find.

The script was put into a field - calculation - custom calculation script.

Both supplyleft and supply rows fields have correctly calculated numbers.

Is that a problem?  Because only the words Pass, Fail and NA are conditional.

The supply average rows are calculated numbers (based on average of supply readings)

try67
Community Expert
Community Expert
August 31, 2018

There must be errors in the console because you made several mistakes in the code.

You used "getfield" instead of "getField", and JS is case-sensitive, so it should have caused something like this to appear in the JS Console:

TypeError: this.getfield is not a function