Verify checkbox and send email

Community Beginner ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

Hello,

I'm working on trying to create a button that will verify that one or the other checkbox has been checked and then would send the pdf to the email of the checked checkbox. I am very new to coding and reading online and in the forums I was able to put this javascript together but it is not working properly and I am not sure what I have done wrong. For the code I have just put in generics to show an example of what I'm trying to create:

Button Code:

//To check checkbox and send email

var cCK = this.getField("CheckBox1", "ChekcBox2").value;

if(cCK=="Off") app.alert ("app message");

else if(this.getField("CheckBox1).value=="Yes")(this.mailDoc({cTo:"email1"});}

else if(this.getField("CheckBox2).value=="Yes")(this.mailDoc({cTo:"email2"});}

 

The error message will pop-up even if one checkbox is checked and it won't attach the pdf to the email, any help on how to remedy this error would be appreciated!

TOPICS
JavaScript , PDF forms

Views

143

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

correct answers 1 Correct answer

Community Expert , May 05, 2022 May 05, 2022

You can do it like this:

var cCK1 = this.getField("CheckBox1").valueAsString;
var cCK2 = this.getField("CheckBox2").valueAsString;
if(cCK1=="Off"&&cCK2=="Off") app.alert ("app message");

else if(cCK1=="Yes")(this.mailDoc({cTo:"email1"});}

else if(cCK2=="Yes")(this.mailDoc({cTo:"email2"});}

 

What should happen if both checkboxes are "Yes"?

You were also missing second parentheses next to both field names in 'else if' lines.

Likes

Translate

Translate
Advocate ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

Hello @JS2014C,

 

I haven't tested your code but I did notice a type-O

//Change this line
var cCK = this.getField("CheckBox1", "ChekcBox2").value;

//To
var cCK = this.getField("CheckBox1", "CheckBox2").value;

Regards,

Mike

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
community guidelines
Community Beginner ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

Thanks for catching that, that is typo in my post (Sorry!)

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
community guidelines
Community Expert ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

It's not a typo, but a mistake. The getField method only takes one parameter.

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
community guidelines
Community Expert ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

You can only use one field name at method getField.

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
community guidelines
Community Beginner ,
May 10, 2022 May 10, 2022

Copy link to clipboard

Copied

Thanks for that info, good to know.

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
community guidelines
Community Expert ,
May 05, 2022 May 05, 2022

Copy link to clipboard

Copied

You can do it like this:

var cCK1 = this.getField("CheckBox1").valueAsString;
var cCK2 = this.getField("CheckBox2").valueAsString;
if(cCK1=="Off"&&cCK2=="Off") app.alert ("app message");

else if(cCK1=="Yes")(this.mailDoc({cTo:"email1"});}

else if(cCK2=="Yes")(this.mailDoc({cTo:"email2"});}

 

What should happen if both checkboxes are "Yes"?

You were also missing second parentheses next to both field names in 'else if' lines.

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
community guidelines
Community Beginner ,
May 10, 2022 May 10, 2022

Copy link to clipboard

Copied

Thank you so much! I was able to make this coding work and added your suggestion about what if they were both yes.

Code used:

var cCK1=this.getField(Checkbox1).valueAsString;

var cCK2=this.getField(Checkbox2).valueAsString;

if(cCK1&&cCK2=="Off")app.alert("app message");

else if(cCK1=="Yes"&&cCK2=="Yes")app.alert("app message");

else if(cCK1=="Yes")this.mailDoc({bUI:true, cTo:"email1});

else if(cCK2=="Yes")this.mailDoc({bUI:true,cTo:"email2});

 

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
community guidelines
Community Expert ,
May 10, 2022 May 10, 2022

Copy link to clipboard

Copied

You are missing quotations in both variables and at the end of both 'email' and this is error too if(cCK1&&cCK2=="Off"), it should look like this:

var cCK1=this.getField("Checkbox1").valueAsString;

var cCK2=this.getField("Checkbox2").valueAsString;

if(cCK1=="Off"&&cCK2=="Off")app.alert("app message");

else if(cCK1=="Yes"&&cCK2=="Yes")app.alert("app message");

else if(cCK1=="Yes")this.mailDoc({bUI:true, cTo:"email1"});

else if(cCK2=="Yes")this.mailDoc({bUI:true,cTo:"email2"});

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
community guidelines
Community Beginner ,
May 10, 2022 May 10, 2022

Copy link to clipboard

Copied

LATEST

Thank you, I will update with those corrections.

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