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

Is there a more efficient way to do this?

New Here ,
Aug 29, 2016 Aug 29, 2016

var Int_Mod = this.getField("INT_Total");

var button_color = this.getField("01").fillColor;

if (button_color.toString() == ["RGB", 1, 1, 1])

{

app.alert("Switch color to Grey, +1 to INT Modifiers");

Int_Mod.value = (this.getField("INT_Total").value - 1);

this.getField("01").fillColor = ["RGB", .5 ,.5 ,.5 ];

}

else if (button_color.toString() == ["RGB", .5, .5, .5] )

{

app.alert("Switch color to Red, +5 to INT Modifiers");

Int_Mod.value = (this.getField("INT_Total").value - 4);

this.getField("01").fillColor = ["RGB", 1, 0, 0 ];

}

else if (button_color.toString() == ["RGB",1, 0, 0])

{

app.alert("Switch color to Black, set INT Modifier to 0");

Int_Mod.value = (this.getField("INT_Total").value + 5);

this.getField("01").fillColor = ["RGB", 0, 0, 0 ];

}

else if (button_color.toString() == ["RGB", 0, 0, 0] )

{

app.alert("Switch color to White, 0 INT Modifiers");

this.getField("01").fillColor = ["RGB", 1, 1, 1];

}

else

{

this.getField("01").fillColor = ["RGB",1,1,1] // in case color is not white when button created

app.alert("default to white")

}

I need about 20 buttons with this code in the Mouse Up Event.  Each button will affect one text field.  I'm wondering if there is a better way to do this, maybe a switch/case?  I don't want to cut/paste/edit the code for each button.

Thank you for looking at this.

TOPICS
Acrobat SDK and JavaScript
323
Translate
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 ,
Aug 29, 2016 Aug 29, 2016

Use a document-level function with args for the field names. Call this function at every button.

Translate
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
New Here ,
Aug 29, 2016 Aug 29, 2016

Can you give me an example.  I'm not really a programmer, I'm just trying to figure this out.

Translate
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 ,
Aug 29, 2016 Aug 29, 2016
LATEST

Examples of JavaScript functions:

JavaScript Function Definitions

Translate
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