Skip to main content
Participant
April 8, 2025
Answered

Need Assistance with If and Else If Statement for PDF Form

  • April 8, 2025
  • 1 reply
  • 354 views

Hi Adobe Community,

 

I need your kind assitance in writing an If and Else If Statement. Please find my situation below.

 

I have two fields named as Vehiclecountduration and Vcd. The Vehiclecountduration is a drop down field with the options - 5 minutes, 15 minutes, 60 minutes and 1 day. This is a required field and thus, the user must choose one of the options. I would like the following to be displayed in the Vcd field.

   If in the drop down list in Vehiclecountduration, 5 minutes is selected then I want 5 to be displayed in the Vcd field.

   If in the drop down list in Vehiclecountduration, 15 minutes is selected then I want 15 to be displayed in the Vcd field.

   If in the drop down list in Vehiclecountduration, 60 minutes is selected then I want 60 to be displayed in the Vcd field.

   If in the drop down list in Vehiclecountduration, 1 day is selected then I want 600 to be displayed in the Vcd field.

 

The Vcd field should be a number field as I want to use it as an input for calculation in another field.

 

I have written the following script but it is giving syntax error after condition. 

 

var nVcd = this.getField("Vehiclecountduration");

if (( event.value = "5 min") {

    nVcd.value  = 5;

}

else if (( event.value = "15 min"){

    nVcd.value  = 15;

}

else if (event.value = "60 min"){

    nVcd.value  = 60;

}

 

else if (event.value = "1 day"){

    nVcd.value  = 600;

}

 

Thank you.

 

Kind Regards,

 

Ridwan Quaium

Correct answer Nesa Nurani

There are a couple of errors:

1. Used wrong field name in variable, it should be: var nVcd = this.getField("Vcd");

2. You have two opening parentheses in first two condition, there should be only one.

3. when comparing you need two equal signs, not one like this: if ( event.value == "5 min") {

 

Use this as custom calculation script of dropdown field:

var nVcd = this.getField("Vcd");

if(event.value == "5 min"){
 nVcd.value = 5;}

else if(event.value == "15 min"){
 nVcd.value = 15;}

else if(event.value == "60 min"){
 nVcd.value = 60;}

else if(event.value == "1 day"){
 nVcd.value = 600;}

There is also another approach much easier, just add numbers as export values of dropdown choices, for example for "5 min" set export value to 5, for "15 min" set export value to 15...etc then you could use this calculation script:

this.getField("Vcd").value = event.value;

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
April 8, 2025

There are a couple of errors:

1. Used wrong field name in variable, it should be: var nVcd = this.getField("Vcd");

2. You have two opening parentheses in first two condition, there should be only one.

3. when comparing you need two equal signs, not one like this: if ( event.value == "5 min") {

 

Use this as custom calculation script of dropdown field:

var nVcd = this.getField("Vcd");

if(event.value == "5 min"){
 nVcd.value = 5;}

else if(event.value == "15 min"){
 nVcd.value = 15;}

else if(event.value == "60 min"){
 nVcd.value = 60;}

else if(event.value == "1 day"){
 nVcd.value = 600;}

There is also another approach much easier, just add numbers as export values of dropdown choices, for example for "5 min" set export value to 5, for "15 min" set export value to 15...etc then you could use this calculation script:

this.getField("Vcd").value = event.value;

Participant
April 9, 2025

Hi Nesa,

Thank you very much for your advice. I did not know about the export value option. I used that and it worked. It was very easy. Thank you again for your time and advice.