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

combining javascripts

Participant ,
Mar 14, 2017 Mar 14, 2017

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.

TOPICS
Acrobat SDK and JavaScript , Windows
782
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

correct answers 1 Correct answer

Community Expert , Mar 15, 2017 Mar 15, 2017

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";

}

Translate
Community Expert ,
Mar 15, 2017 Mar 15, 2017

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

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
Participant ,
Mar 15, 2017 Mar 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?

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 ,
Mar 15, 2017 Mar 15, 2017

Something like this:

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

if (f.valueAsString=="") {

  ...

} else {

  ...

}

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
Participant ,
Mar 15, 2017 Mar 15, 2017

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.

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 ,
Mar 15, 2017 Mar 15, 2017

What code do you use?

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 ,
Mar 15, 2017 Mar 15, 2017

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";

}

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
Participant ,
Mar 16, 2017 Mar 16, 2017
LATEST

Thank you, Mr Kremer, I examined the code and I learned a bit from it.

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