How do you show/hide buttons based on calculated result

Aug 23, 2017

Copy link to clipboard

Copied

Hi,

I'm struggling with this; hopefully someone can help.

I'm creating a PDF that has some questions that are radio buttons with numeric values on each one. I'm wanting the sum of those selected to show a particular button - the result.

I've done something similar in the past, however that just populates a field with predefined text and colours the box - in this instance I'm wanting to show/hide a button as I was hoping to do a graphical answer as opposed to just words.

Here's the script I'd use previously:

var nResult = this.getField(“XXXXXX”).value;

if ( nResult > 14 ) {

event.value = “XXXXXXX”;

event.target.textColor = ["RGB", 1, 1, 1];

event.target.fillColor = ["RGB", 0, 0.454902, 0.482353];

}

else if( nResult > 7 ) {

event.value = “XXXXXXX”;

event.target.textColor = ["RGB", 0.113725, 0.113725, 0.105882];

event.target.fillColor = ["RGB", 1, 0.780392, 0.345098];

}

else {

event.value = “XXXXXXXXX”;

event.target.textColor = ["RGB", 0.113725, 0.113725, 0.105882];

event.target.fillColor = ["RGB", 0.937255, 0.262745, 0.219608];

}

Can this be done? any help would be hugely appreciated.

Huge thanks in advance

Sure. To show a field use this code:

this.getField("Button1").display = display.visible;

To hide it:

this.getField("Button1").display = display.hidden;

TOPICS
Acrobat SDK and JavaScript

Views

412

Likes

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

How do you show/hide buttons based on calculated result

Aug 23, 2017

Copy link to clipboard

Copied

Hi,

I'm struggling with this; hopefully someone can help.

I'm creating a PDF that has some questions that are radio buttons with numeric values on each one. I'm wanting the sum of those selected to show a particular button - the result.

I've done something similar in the past, however that just populates a field with predefined text and colours the box - in this instance I'm wanting to show/hide a button as I was hoping to do a graphical answer as opposed to just words.

Here's the script I'd use previously:

var nResult = this.getField(“XXXXXX”).value;

if ( nResult > 14 ) {

event.value = “XXXXXXX”;

event.target.textColor = ["RGB", 1, 1, 1];

event.target.fillColor = ["RGB", 0, 0.454902, 0.482353];

}

else if( nResult > 7 ) {

event.value = “XXXXXXX”;

event.target.textColor = ["RGB", 0.113725, 0.113725, 0.105882];

event.target.fillColor = ["RGB", 1, 0.780392, 0.345098];

}

else {

event.value = “XXXXXXXXX”;

event.target.textColor = ["RGB", 0.113725, 0.113725, 0.105882];

event.target.fillColor = ["RGB", 0.937255, 0.262745, 0.219608];

}

Can this be done? any help would be hugely appreciated.

Huge thanks in advance

Sure. To show a field use this code:

this.getField("Button1").display = display.visible;

To hide it:

this.getField("Button1").display = display.hidden;

TOPICS
Acrobat SDK and JavaScript

Views

413

Likes

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
Aug 23, 2017 0
Aug 23, 2017

Copy link to clipboard

Copied

Sure. To show a field use this code:

this.getField("Button1").display = display.visible;

To hide it:

this.getField("Button1").display = display.hidden;

Likes

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
Reply
Loading...
Aug 23, 2017 1
Aug 23, 2017

Copy link to clipboard

Copied

Hi Try67,

Great - thank you so, just to make sure i'm not being stupid - my code would be something like this?

var nResult = this.getField("XXXXXX").value;

if ( nResult > 14 ) {

this.getField("Button1").display = display.visible;

this.getField("Button2").display = display.hidden;

this.getField("Button3").display = display.hidden;

}

else if( nResult > 7 ) {

this.getField("Button1").display = display.hidden;

this.getField("Button2").display = display.visible;

this.getField("Button3").display = display.hidden;

}

else {

this.getField("Button1").display = display.hidden;

this.getField("Button2").display = display.hidden;

this.getField("Button3").display = display.visible;

}

Thanks

Likes

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
Reply
Loading...
Aug 23, 2017 0
Aug 23, 2017

Copy link to clipboard

Copied

That looks fine, yes.

On Wed, Aug 23, 2017 at 12:00 PM, soulglowdeej <forums_noreply@adobe.com>

Likes

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
Reply
Loading...
Aug 23, 2017 1
Aug 23, 2017

Copy link to clipboard

Copied

Great!!

Thanks so much Try67 - works perfectly.

Likes

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
Reply
Loading...
Aug 23, 2017 0