• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Using a loop with switch event on text fields

Engaged ,
Jul 07, 2022 Jul 07, 2022

Copy link to clipboard

Copied

Is is possible to apply a loop into one text field, instead entering the following custom validation script into each Employee 1 to 5 text fields that switch the AbsencePayTypeDesc 1 to 5 fields?  I've attached a simplified version of what I need but my actual PDF has 25 lines and it's a bit time consuming when I have to update it.  Any help would be greatly appreciated.  Thanks so much!

 

switch (event.value) {
case "Kerry":
var fields = ["AbsencePayTypeDesc1"];
for (var i in fields) this.getField(fields[i]).setItems([" ","Vacation (Kerry)","Sick (Kerry)"]);
break;
case "Derek":
var fields = ["AbsencePayTypeDesc1"];
for (var i in fields) this.getField(fields[i]).setItems([" ","Vacation (Derek)","Sick (Derek)"]);
break;}

 

 

TOPICS
JavaScript , PDF forms

Views

494

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

Community Expert , Jul 08, 2022 Jul 08, 2022

As document level script use like this:

function setDropdowns(field){

switch (event.value) {
case "Kerry":
field.setItems([" ","Vacation (Kerry)","Sick (Kerry)"]);
break;
case "Derek":
field.setItems([" ","Vacation (Derek)","Sick (Derek)"]);
break;
default:
field.clearItems();}
}

Now just call a function in each field as validation script like this:

for first field:

setDropdowns(this.getField("AbsencePayTypeDesc1"));

for second:

setDropdowns(this.getField("AbsencePayTypeDesc2"));  ...etc

To set

...

Votes

Translate

Translate
Community Expert ,
Jul 07, 2022 Jul 07, 2022

Copy link to clipboard

Copied

You can use a function and the field name as parameter of the function.

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 ,
Jul 08, 2022 Jul 08, 2022

Copy link to clipboard

Copied

As document level script use like this:

function setDropdowns(field){

switch (event.value) {
case "Kerry":
field.setItems([" ","Vacation (Kerry)","Sick (Kerry)"]);
break;
case "Derek":
field.setItems([" ","Vacation (Derek)","Sick (Derek)"]);
break;
default:
field.clearItems();}
}

Now just call a function in each field as validation script like this:

for first field:

setDropdowns(this.getField("AbsencePayTypeDesc1"));

for second:

setDropdowns(this.getField("AbsencePayTypeDesc2"));  ...etc

To set document level script select 'Prepare form' tool, click on 'More' then 'Document JavaScript', give script a name and click 'add' and paste script I gave you inside.

 

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
Engaged ,
Jul 08, 2022 Jul 08, 2022

Copy link to clipboard

Copied

LATEST

Thank you Nesa!!  That works beautifully!!

 

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