Copy link to clipboard
Copied
I'm a total beginner and I have "elementary shcool" level of Javascript knowledge.
With google's help, I was able to get a button, that sends an email with custom subject and body using data from the fields in the form, working.
Where I have a problem is when checking if a field is empty. The form has 3 field names.
First one is always filled out so I don't need to check. 2nd and 3rd ones however I need to check if they are empty so I can include them in the email or not.
When I use the code below the script doesn't even run when I press the button which leads me to think that there's an error and that's why it doen't run.
Besides of "valueAsString" I have also tried just "value" but I get the same result.
I also tried the === instead of the ==
Any ideas what I'm doing wrong?
The code I use is:
var RR2Name = this.getField("RR1Name").valueAsString;
var RR2Name = this.getField("RR2Name").valueAsString;
var emailSubject;
if (RR2Name =="") {
emailSubject = RR1Name + " form"
} else {
emailSubject = RR1Name + " and " + RR2 + " form"
}
Copy link to clipboard
Copied
You named both variables 'RR2Name' and in the script you use RR1Name, so change one to RR1Name.
There may be other issue, it is best to post full script if you still have issues.
Copy link to clipboard
Copied
My appologies Nesa. They are in fact RR1Name and RR2Name. When I was copying from my work computer I mistyped and I can't find a way to correct my post.
Copy link to clipboard
Copied
Check the JavaScript console for errors.
Copy link to clipboard
Copied
I don't see any errors. I'll post the whole code when I get back home. Maybe it's something else.
Copy link to clipboard
Copied
If a field value is a single space, Is is empty? If so, then your code won't detect it.
Maybe you should expand the empty field test so that misc white space is part of the empty test.
var RR1Name = this.getField("RR1Name").valueAsString;
var RR2Name = this.getField("RR2Name").valueAsString;
var emailSubject;
// Create regular expression for detecting text
// composed solely of 0 or more white spaces, i.e., blanks.
var rgEmpty = /^\s*$/;
if (rgEmpty.test(RR2Name)) {
emailSubject = RR1Name + " form"
} else {
emailSubject = RR1Name + " and " + RR2 + " form"
}
You might also be interested in this article:
https://acrobatusers.com/tutorials/dynamically-setting-submit-e-mail-address/
Copy link to clipboard
Copied
You need to post the full code or share the file. This is not enough information to know what's wrong.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now