merge multiple if queries?

Community Beginner ,
Aug 22, 2018

Copy link to clipboard

Copied

Hii,

I have three if query.

If I add only one IF-Statment, then this query works., but when I put all three together, the if-statemants do not work.

//This if, disable all Checkbox and textfields

if (this.getField("Bewerbung_post").value == "Ja") {

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

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

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

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

} else {

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

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

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

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

}

if (this.getField("Bewerbung_elektronisch").value == "Ja") {

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

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

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

} else {

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

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

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

}

if (this.getField("Bewerbung_telefonisch").value == "Ja") {

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

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

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

} else {

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

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

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

}

Do I have to build the if-statment differently?

I am new to Java Scripting, so I am grateful for every tip.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Here's an improved version of the code above:

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

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

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

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

if (this.getField("Bewerbung_post").value != "Ja") {

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

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

} else {

    this.resetForm(["Bewerbung_elektronisch", "Email_Adresse", "Bewerbung_telefonisch", "Telefonnummer_Kontaktperson"]);

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

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

}

if (this.getField("Bewerbung_elektronisch").value == "Ja") {

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

}

if (this.getField("Bewerbung_telefonisch").value == "Ja") {

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

}

It works pretty well. See: https://drive.google.com/open?id=1Ub-IY_81cQu0rul1Mm9PwqSIyg66n3oW

TOPICS
Acrobat SDK and JavaScript, Windows

Views

196

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

merge multiple if queries?

Community Beginner ,
Aug 22, 2018

Copy link to clipboard

Copied

Hii,

I have three if query.

If I add only one IF-Statment, then this query works., but when I put all three together, the if-statemants do not work.

//This if, disable all Checkbox and textfields

if (this.getField("Bewerbung_post").value == "Ja") {

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

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

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

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

} else {

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

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

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

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

}

if (this.getField("Bewerbung_elektronisch").value == "Ja") {

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

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

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

} else {

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

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

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

}

if (this.getField("Bewerbung_telefonisch").value == "Ja") {

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

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

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

} else {

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

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

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

}

Do I have to build the if-statment differently?

I am new to Java Scripting, so I am grateful for every tip.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Here's an improved version of the code above:

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

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

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

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

if (this.getField("Bewerbung_post").value != "Ja") {

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

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

} else {

    this.resetForm(["Bewerbung_elektronisch", "Email_Adresse", "Bewerbung_telefonisch", "Telefonnummer_Kontaktperson"]);

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

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

}

if (this.getField("Bewerbung_elektronisch").value == "Ja") {

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

}

if (this.getField("Bewerbung_telefonisch").value == "Ja") {

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

}

It works pretty well. See: https://drive.google.com/open?id=1Ub-IY_81cQu0rul1Mm9PwqSIyg66n3oW

TOPICS
Acrobat SDK and JavaScript, Windows

Views

197

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 22, 2018 0
Most Valuable Participant ,
Aug 22, 2018

Copy link to clipboard

Copied

The first step is to clearly define, for each field, when it should be visible and when not.

For example, "Bewerbung_elektronisch". Should it be visible if "Bewerbung_telefonisch" is not "Ja" AND "Bewerbung_post" is not "Ja"?

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 22, 2018 0
Community Beginner ,
Aug 22, 2018

Copy link to clipboard

Copied

i think the best way to explain it is with this pictures

the first if-statemant

bwerbung_post.png

the second if-statemant

bewerbung_elektronisch.png

the third if-statemant

bwerbung_telefonisch.png

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 22, 2018 0
Most Valuable Participant ,
Aug 22, 2018

Copy link to clipboard

Copied

Can you share the actual file with us, or at least specify the names of all of these fields? Your code seems to reference more fields than those in your screenshots...

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 22, 2018 0
Most Valuable Participant ,
Aug 22, 2018

Copy link to clipboard

Copied

Try this code as the custom calculation script of a separate (hidden) text field:

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

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

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

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

if (this.getField("Bewerbung_post").value != "Ja") {

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

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

}

if (this.getField("Bewerbung_elektronisch").value == "Ja") {

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

}

if (this.getField("Bewerbung_telefonisch").value == "Ja") {

    this.getField("Telefonnummer_Kontaktperson").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...
Aug 22, 2018 0
Community Beginner ,
Aug 22, 2018

Copy link to clipboard

Copied

Here are the link to download this form:

File

i hope it works

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 22, 2018 0
Most Valuable Participant ,
Aug 22, 2018

Copy link to clipboard

Copied

Here's an improved version of the code above:

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

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

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

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

if (this.getField("Bewerbung_post").value != "Ja") {

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

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

} else {

    this.resetForm(["Bewerbung_elektronisch", "Email_Adresse", "Bewerbung_telefonisch", "Telefonnummer_Kontaktperson"]);

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

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

}

if (this.getField("Bewerbung_elektronisch").value == "Ja") {

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

}

if (this.getField("Bewerbung_telefonisch").value == "Ja") {

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

}

It works pretty well. See: https://drive.google.com/open?id=1Ub-IY_81cQu0rul1Mm9PwqSIyg66n3oW

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 22, 2018 0
Most Valuable Participant ,
Aug 22, 2018

Copy link to clipboard

Copied

Actually, change the last part to:

if (this.getField("Bewerbung_elektronisch").value == "Ja") {

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

} else this.resetForm(["Email_Adresse"]);

if (this.getField("Bewerbung_telefonisch").value == "Ja") {

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

} else this.resetForm(["Telefonnummer_Kontaktperson"]);

This makes sure that if the user un-ticks those boxes, the associated text fields are cleared.

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 22, 2018 0
Community Beginner ,
Aug 22, 2018

Copy link to clipboard

Copied

Hi

thanks a lot, it works correctly.. you saved my day

great community!!

best regards

dashmir

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 22, 2018 0
Adobe Community Professional ,
Aug 22, 2018

Copy link to clipboard

Copied

You must use something like this:

if (this.getField("Bewerbung_post").value == "Ja") {

...

} else if (this.getField("Bewerbung_elektronisch").value == "Ja") {

...

} else if (this.getField("Bewerbung_telefonisch").value == "Ja") {

...

   

} else {

...

}

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 22, 2018 0
Community Beginner ,
Aug 22, 2018

Copy link to clipboard

Copied

Hi Bernd

thanks for your answer.

That was my guess, but I'm not sure how to do it that way.

i had share the file. maybe we will find a solution.

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 22, 2018 0