Building Multiple If Statements to Show a Field or Change Message Text

New Here ,
Nov 21, 2018

Copy link to clipboard

Copied

Hi All,

I'm fairly new to javascript. I've been working my way up more complex combinations, but I can't seem to figure this one out. I'm trying to get the results of two sets of radio buttons to determine whether multiple fields are shown and which message comes up when clicking the submit button.

If button 1 = yes and button 2 = yes, I need to show fields 3, 4, 5.

If button 1 = yes and button 2 = no, I need to show field 6.

If button 1 = no and button 2 = no, I don't show any fields.

I've been at this all day and unable to write the script that works. PLEASE Help!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

OK. I would do it using a hidden text field's custom calculation event, and this code:

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

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

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

var v1 = this.getField("LendingLimit").valueAsString;

var v2 = this.getField("LoanAmount").valueAsString;

if (v1=="No" && v2=="UW") {

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

}

if (v1=="No" && v2=="NoUW") {

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

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

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

202

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

Building Multiple If Statements to Show a Field or Change Message Text

New Here ,
Nov 21, 2018

Copy link to clipboard

Copied

Hi All,

I'm fairly new to javascript. I've been working my way up more complex combinations, but I can't seem to figure this one out. I'm trying to get the results of two sets of radio buttons to determine whether multiple fields are shown and which message comes up when clicking the submit button.

If button 1 = yes and button 2 = yes, I need to show fields 3, 4, 5.

If button 1 = yes and button 2 = no, I need to show field 6.

If button 1 = no and button 2 = no, I don't show any fields.

I've been at this all day and unable to write the script that works. PLEASE Help!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

OK. I would do it using a hidden text field's custom calculation event, and this code:

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

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

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

var v1 = this.getField("LendingLimit").valueAsString;

var v2 = this.getField("LoanAmount").valueAsString;

if (v1=="No" && v2=="UW") {

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

}

if (v1=="No" && v2=="NoUW") {

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

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

}

TOPICS
Acrobat SDK and JavaScript, Windows

Views

203

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
Nov 21, 2018 0
Most Valuable Participant ,
Nov 21, 2018

Copy link to clipboard

Copied

What if one, or both, of the fields don't have any value selected at all?

What if 1 = no and 2 = yes?

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...
Nov 21, 2018 0
New Here ,
Nov 21, 2018

Copy link to clipboard

Copied

Great question! They are both required fields. I wouldn't want any action until both were filled out. Fields 3-6 are all hidden by default. I'm not sure if I should be putting this script in the calculation of each field I want to show or hide, or run it based an a mouse up of field 2.

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...
Nov 21, 2018 0
New Here ,
Nov 21, 2018

Copy link to clipboard

Copied

If 1=no and 2=yes, I don't need to show any fields.

As a side note: your responses on other posts have been incredibly helpful as I learn to write this on my own. Very well written.

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...
Nov 21, 2018 0
Most Valuable Participant ,
Nov 21, 2018

Copy link to clipboard

Copied

It's important to understand that the "required" property only comes into play when the file is submitted. The fact they are required doesn't mean that they can't be blank, and it's good practice to take all possible combinations into consideration.

What are the actual names of all the fields involved in this?

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...
Nov 21, 2018 0
New Here ,
Nov 21, 2018

Copy link to clipboard

Copied

Understood on that required piece - thank you!

Field names and values are below, along with the combinations.

"LendingLimit" value = Yes + "LoanAmount" value = UW : Nothing to show

"LendingLimit" value = Yes + "LoanAmount" value = NoUW: Nothing to show

"LendingLimit" value = No + "LoanAmount" value = UW : Show "UW_Verify"

"LendingLimit" value = No + "LoanAmount" value = NoUW: Show "Signature_Text" and "Signature_Box"

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...
Nov 21, 2018 0
Most Valuable Participant ,
Nov 21, 2018

Copy link to clipboard

Copied

OK. I would do it using a hidden text field's custom calculation event, and this code:

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

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

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

var v1 = this.getField("LendingLimit").valueAsString;

var v2 = this.getField("LoanAmount").valueAsString;

if (v1=="No" && v2=="UW") {

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

}

if (v1=="No" && v2=="NoUW") {

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

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

}

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...
Nov 21, 2018 1
New Here ,
Nov 21, 2018

Copy link to clipboard

Copied

Has anyone told you today yet that you are AMAZING?!

That works perfectly. Thank you so much. Any recommendation for education for a noob like myself? I'd like to get in a class for this.

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...
Nov 21, 2018 0
try67 LATEST
Most Valuable Participant ,
Nov 21, 2018

Copy link to clipboard

Copied

Thanks, that's nice to hear!

Here are a couple of good resources about JavaScript in general and in Acrobat in particular:

General JS tutorial (note that only the core syntax applies to Acrobat, though): JavaScript Tutorial

Homepage for Acrobat JavaScript development, including a link to the full API: Adobe - Acrobat Developer Center | Adobe Developer Connection

Free tutorials about Acrobat in general, including many JS related ones: https://acrobatusers.com/tutorials/

A paid-for website with tutorials about Acrobat JavaScript (not related to me): http://www.pdfscripting.com/

My humble web-site with many tools for Acrobat (mostly paid-for, some free): Custom-made Adobe Scripts

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...
Nov 21, 2018 0