Copy link to clipboard
Copied
I am very new to acrobat form JavaScript and to coding in general. I have scoured the internet looking for my answers, but nothing quite fits. Your help would be greatly appreciated.
I have a 2-page document with various form fields in rows - 16 rows total. At the beginning of each row is a checkbox that I use (via JavaScript) to clear the contents of the entire row, if needed. Besides the initial checkbox, each row contains 5 text boxes, 4 date pickers, and 9 additional checkboxes.
I have a button with the mouse up set to run a JavaScript using the this.mailDoc code to send form data via email. However, I want to conditionally send information to the body of the email based on checkboxes being enabled.
Here is what I want to do:
1) If the row's initial checkbox is enabled, I want the data from certain fields in the row to be sent to the body of the email. If the row's initial checkbox is disabled, I don't want any of the data from the row's various fields sent to the body of the email. (In the case of a disabled checkbox at the beginning of the row, there won't be any entries in the text and date fields and the checkboxes will all be disabled, but the script below will still send data from the disabled checkboxes (i.e., "Off").
2) Even when the initial checkbox is enabled, I only want certain data sent to the body of the email. I want data from the text boxes sent. However, I only want data sent from checkboxes if they are disabled (basically a to-do item... if unchecked, still needs to be done). I assume I can use the export value of the checkbox to send the data, but I need an if statement send the export value only when it is unchecked or disabled and to send nothing if it is checked or enabled.
Here is the code I have so far. It only addresses the first two text boxes and the first two checkboxes in the first two rows (not the checkbox that I want to use to control the data going to the body of the email). The initial checkbox at each row (the conditional control checkbox) is named CheckBox1 for row one, CheckBox2 for row two, etc...
var returnemail = "MAT TEAM"
var destemail = "my email@mycompany.com"
var Text_prog_1Field = this.getField("Text_prog_1");
var Text_name_1Field = this.getField("Text_name_1");
var Check_fam_1Field = this.getField("Check_fam_1");
var Check_ref_1Field = this.getField("Check_ref_1");
var Text_prog_2Field = this.getField("Text_prog_2");
var Text_name_2Field = this.getField("Text_name_2");
var Check_fam_2Field = this.getField("Check_fam_2");
var Check_ref_2Field = this.getField("Check_ref_2");
var subline = "MAT Team Roster"
var emailBody =
Text_prog_1Field.valueAsString + ", " + Text_name_1Field.valueAsString + ":" + "\n" +
Check_fam_1Field.valueAsString + "\n" +
Check_ref_1Field.valueAsString + "\n" + "\n" +
Text_prog_2Field.valueAsString + ", " + Text_name_2Field.valueAsString + ":" + "\n" +
Check_fam_2Field.valueAsString + "\n" +
Check_ref_2Field.valueAsString;
this.mailDoc({bUI: true, cTo: returnemail, cCc: destemail, cSubject: subline, cMsg: emailBody});
I appreciate the help!
The basic code for doing it is something like this:
var emailMsg = "";
if (this.getField("Checkbox1").valueAsString!="Off") emailMsg+=this.getField("Text1").valueAsString + ", ";
if (this.getField("Checkbox2").valueAsString!="Off") emailMsg+=this.getField("Text2").valueAsString + ", ";
etc.
Copy link to clipboard
Copied
Here are a couple of articles that will help, both come with links to sample files:
https://acrobatusers.com/tutorials/conditional-execution
https://acrobatusers.com/tutorials/dynamically-setting-submit-e-mail-address
Copy link to clipboard
Copied
Thank you Thom, your articles have been fantastic. I read them several times prior to posting. I still haven't been able to get the code to work. Additional help from the group would be greatly appreciated.
Copy link to clipboard
Copied
The basic code for doing it is something like this:
var emailMsg = "";
if (this.getField("Checkbox1").valueAsString!="Off") emailMsg+=this.getField("Text1").valueAsString + ", ";
if (this.getField("Checkbox2").valueAsString!="Off") emailMsg+=this.getField("Text2").valueAsString + ", ";
etc.
Copy link to clipboard
Copied
Thanks Try67! This really helped me out - I modified the code you posted and it worked well. Much appreciated!