Skip to main content
Participant
August 29, 2016
Question

Is there a more efficient way to do this?

  • August 29, 2016
  • 1 reply
  • 370 views

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.

This topic has been closed for replies.

1 reply

Bernd Alheit
Community Expert
Community Expert
August 29, 2016

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

Participant
August 29, 2016

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

Bernd Alheit
Community Expert
Community Expert
August 29, 2016

Examples of JavaScript functions:

JavaScript Function Definitions