Skip to main content
New Participant
December 5, 2018
Answered

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

  • December 5, 2018
  • 1 reply
  • 1941 views

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 has been closed for replies.
Correct answer try67

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

else event.value = "";

1 reply

try67
Community Expert
December 5, 2018

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

New Participant
December 5, 2018

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;

}

try67
try67Correct answer
Community Expert
December 5, 2018

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

else event.value = "";