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

Is there an easier way to write this script?

New Here ,
May 25, 2018 May 25, 2018

Copy link to clipboard

Copied

I am working on a custom format script for a dropdown field and i keep getting an error that the script is to long for the dialog box. I am fairly new to this and I think there is a way to write the script below to save time and space. This is just a sample of the entire script.

var f = event.target;var pos = f.currentValueIndices; //position sélectionnée

if (event.value=="                                       Select Wildlife Management Activity")

this.getField("Caption1").value = "";

if (event.value=="                          Habitat Control - Range Enhancement (Re-seeding)")

this.getField("Caption1").value = "Reseeding for XX with XX\nDate:\nTotal Acres:";

if (event.value=="                                       Habitat Control - Brush Management")

this.getField("Caption1").value = "XX Removal\nDate:\nTotal Acres";

var f = event.target;

var pos = f.currentValueIndices; //position sélectionnée

if (event.value=="                                       Select Wildlife Management Activity")

this.getField("Caption2").value = "";

if (event.value=="                          Habitat Control - Range Enhancement (Re-seeding)")

this.getField("Caption2").value = "Reseeding for XX with XX\nDate:\nTotal Acres:";

if (event.value=="                                       Habitat Control - Brush Management")

this.getField("Caption2").value = "XX Removal\nDate:\nTotal Acres";

var f = event.target;var pos = f.currentValueIndices; //position sélectionnée

if (event.value=="                                       Select Wildlife Management Activity")

this.getField("TEXT").value = "";

if (event.value=="                          Habitat Control - Range Enhancement (Re-seeding)")

this.getField("TEXT").value = "Reseeding for XX with XX\nDate:\nTotal Acres:";

if (event.value=="                                       Habitat Control - Brush Management")

this.getField("TEXT").value = "XX Removal\nDate:\nTotal Acres";

TOPICS
Acrobat SDK and JavaScript

Views

300

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

LEGEND , May 25, 2018 May 25, 2018

Change the default built-in editor to an external text editor. Text editors are not Word or other word processing program. Examples are Textpad or Notepad plus.

Votes

Translate

Translate
LEGEND ,
May 25, 2018 May 25, 2018

Copy link to clipboard

Copied

Change the default built-in editor to an external text editor. Text editors are not Word or other word processing program. Examples are Textpad or Notepad plus.

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 ,
May 25, 2018 May 25, 2018

Copy link to clipboard

Copied

You can shorten your code by using variables. Instead of referring to the same field multiple times like this:

this.getField("Caption1").value = ...

Change it to:

var f1 = this.getField("Caption1");

f1.value = ...

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
LEGEND ,
May 25, 2018 May 25, 2018

Copy link to clipboard

Copied

LATEST

If you are trying to see if required fields have been completed, there are other ways that include looping through the fields and testing the "required" property's value and then testing to see if the current value is that same as the field's default value and setting a control flag for later processing or adding the field name to an array of incomplete fields. The number of lines for this type of solution remains the same no matter how many fields are in the form.

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