Skip to main content
Known Participant
March 15, 2017
Answered

combining javascripts

  • March 15, 2017
  • 1 reply
  • 912 views

Can someone tell me how to combine these three scripts so they will function as one? Each script functions but I'd like to have them work like this, the alignment would be set to left when Item.1 is visible and return to align center when hidden.

First script:

var f = this.getField("Item.1");

f.display = (f.valueAsString=="") ? display.hidden : display.visible;

Second script:

var f = this.getField("Item.1");

f.alignment = "center";

Third script:

var f = this.getField("Item.1");

f.alignment = "left";

Is this possible? Thank you.

This topic has been closed for replies.
Correct answer Karl Heinz Kremer

Hello Bernd, thanks for the reply with the script, but sorry to say I keep getting "Syntax Error" and I'm not so experienced with javascript to figure it out. Or, how to modify the code.


You will have to fill in the missing parts 0 where Bernd used ... to indicate that something is missing. Based on your description, this should work:

var f = this.getField("Item.1");

if (f.valueAsString == "") {

  f.display = display.hidden;

  f.alignment = "center";

} else {

  f.display = display.visible;

  f.alignment = "left";

}

1 reply

Bernd Alheit
Community Expert
Community Expert
March 15, 2017

Why want you set the alignment to center when the field is not visible and empty?

pdfUser1Author
Known Participant
March 15, 2017

Little difficult to explain. The easiest explanation is, I have other button to show/hide those fields. Do you know how to combine the scripts as I requested in my post?

Bernd Alheit
Community Expert
Community Expert
March 15, 2017

Something like this:

var f = this.getField("Item.1");

if (f.valueAsString=="") {

  ...

} else {

  ...

}