Skip to main content
Participant
Dec 5, 2018 10:53 PM UTC
Answered

If an input field is != null display a integer in the output

Hi Everyone

I want my program to detect if a field has an entry and if it has an entry set the output field to a value. Currently the program gets stuck on the if statement.

The following code is in custom calculation script. Running on Adobe Acrobat Pro 2017. Also if there is a easier way to do this please let me know, thanks in advance.

var nameOne = this.getField("Name1").valueAsString;

var nameTwo = this.getField("Name2").valueAsString;

var nameThree = this.getField("Name3").valueAsString;

var nameFour = this.getField("Name4").valueAsString;

var nameFive = this.getField("Name5").valueAsString;

if( nameOne != "null"){

    event.value=1;

}

else if(nameOne && nameTwo != "null"){

event.value= 2;

}

else if(nameOne && nameTwo && nameThree != "null"){

event.value= 3;

}

else if(nameOne && nameTwo && nameThree && nameFour != "null"){

event.value= 4;

}

else if(nameOne && nameTwo && nameThree && nameFour && nameFive != "null"){

event.value= 5;

}

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Dec 5, 2018 11:23 PM UTC

You should add something like this at the end of the code:

else event.value = "";

6 replies

try67
Community Expert
Community Expert
Dec 5, 2018 10:59 PM UTC

The valueAsString property can't return null, only strings. Replace all instances of "null" in your code with "", therefore.

Translate
Participant
Dec 5, 2018 11:19 PM UTC

Thanks for the reply. I have changed the code to as shown; however, is still returns 1

if( nameOne != ""){

    event.value=1;

}

else if(nameOne && nameTwo != ""){

event.value= 2;

}

else if(nameOne && nameTwo && nameThree != ""){

event.value= 3;

}

else if(nameOne && nameTwo && nameThree && nameFour.value != ""){

event.value= 4;

}

else if(nameOne && nameTwo && nameThree && nameFour && nameFive != ""){

event.value= 5;

}

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Dec 5, 2018 11:23 PM UTC

You should add something like this at the end of the code:

else event.value = "";

Translate