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

If Else based of user selected fields

New Here ,
May 03, 2019 May 03, 2019

Copy link to clipboard

Copied

Hello,

Looking for some help with If Else statements in a PDF. What I would like to accomplish is changing the wording of an email subject and body based off the user choices in a drop down.

Basically if the user selects "yes" from a dropd own titled "Repair Req" when they need a repair request when submitting the form, the email subject line and body wording will change. If the user selects "no", then the subject and body are different.

var cToAddr = “user1@email.com”;

var cCCAddr = "user2@email.com;

if(this.getField("Repair Req").value!="Yes") {

var cSubLine = "FINAL w/ REPAIR REQUEST“;

var cBody = "Repair Request”;

}

else{

var cSubLine = "FINAL";

var cBody = "Final”;

}

this.mailDoc({bUI:true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine, cMsg: cBody});

TOPICS
Acrobat SDK and JavaScript , Windows

Views

486

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
community guidelines

correct answers 1 Correct answer

Community Expert , May 03, 2019 May 03, 2019

Well, you've introduced another error in this version.

Use this code:

var cToAddr = "user1@email.com";

var cCCAddr = "user2@email.com";

var cSubLine, cBody;

if (this.getField("Repair Req").value=="Yes") {

    cSubLine = "FINAL w/ REPAIR REQUEST";

    cBody = "Repair Request";

} else {

    cSubLine = "FINAL";

    cBody = "Final";

}

this.mailDoc({bUI:true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine, cMsg: cBody});

Votes

Translate

Translate
Community Expert ,
May 03, 2019 May 03, 2019

Copy link to clipboard

Copied

Your code looks almost fine, and I believe it should work despite the issues of where you're declaring the variables in it, because JS is very lenient with that. Is it not working?

Votes

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
community guidelines
New Here ,
May 03, 2019 May 03, 2019

Copy link to clipboard

Copied

No...it doesnt...I am not well versed in JS at all...so I am feeling my way through. I have tried removing the "!" in the if statement and when the user hits the submit button it changes the value of the Repair Request drop down from "No" to "Yes".

if(this.getField("Repair Req").value="Yes") {

var cSubLine = "FINAL w/ REPAIR REQUEST“;

var cBody = "Repair Request”;

}

else{

var cSubLine = "FINAL";

var cBody = "Final”;

}

Votes

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
community guidelines
Community Expert ,
May 03, 2019 May 03, 2019

Copy link to clipboard

Copied

Well, you've introduced another error in this version.

Use this code:

var cToAddr = "user1@email.com";

var cCCAddr = "user2@email.com";

var cSubLine, cBody;

if (this.getField("Repair Req").value=="Yes") {

    cSubLine = "FINAL w/ REPAIR REQUEST";

    cBody = "Repair Request";

} else {

    cSubLine = "FINAL";

    cBody = "Final";

}

this.mailDoc({bUI:true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine, cMsg: cBody});

Votes

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
community guidelines
New Here ,
May 03, 2019 May 03, 2019

Copy link to clipboard

Copied

LATEST

Awesome! That worked! You folks kick butts! Thank you so much!

Votes

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
community guidelines
Community Expert ,
May 03, 2019 May 03, 2019

Copy link to clipboard

Copied

Remove var before cSubLine and cBody.

Votes

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
community guidelines
Community Expert ,
May 03, 2019 May 03, 2019

Copy link to clipboard

Copied

Ah, I'm noticing two errors now that will stop it from working.

In the first line you're using non-conventional quotes. You must only use straight quotes.

And in the second line you're missing the closing quotes after the email address.

Both errors should cause an error message to appear in the JS Console when you try to run the code, though.

Votes

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
community guidelines