I have a lengthy e-mail script in which one of the fields sometimes contains an ampersand as a value, e.g., "Litigation & Enforcement". The value is set in a drop-down earlier in the form. When the field has a value like that, it cancels everything that comes after that point in the e-mail script, because it interprets it as a "&" which is used to build the body of the script. Is there are any way to have it ignore the ampersand in the field value or do I have to change my values in the drop-down? Thanks for any help.
Hey genel89623801, that did the trick! I had definitely not gotten past the issue and had resigned myself to replacing the ampersand with "and".
Using the encodeURIComponent function wouldn't work for me within the body of the e-mail script, though I tried using value,rawValue and full XFA path notation with it. But it did work when I replaced the ampersand in a variable first, outside of the e-mail script, as below. I consider resolving this minor annoyance a great success. Thanks for the help.
var str = DeptName.rawValue;
var Department = str.replace(/\&/, encodeURIComponent("%26"));
Yes, I eventually had to do that. Before the e-mail is generated I just take the value of the department and convert any ampersands to the word "and". They bosses want to keep the "&" in the names in the drop-downs since that's how they're officially written. Thanks again for the replies.
Seems the %26 only works in a mailto hyperlink and the Doc.mailForm/mailDoc methods. The problem is the "&" character is used as a delimiter in the mailto protocol. Seems the submit email button is expecting one of the key words, (that is to, cc, bcc, body or subject) , doesn't find it so gives up.
Maybe someone else know how to escape the "&" but might be quicker to change the values in the drop down.
Thanks for the responses. Sorry genel89623801, but I don't understand the suggestion. Where my script is having trouble is in the body of the e-mail where the "Department" field is (line 7). Some department names have an ampersand in them (e.g., Litigation & Enforcement), so the script just breaks right at that point.
Thanks for your reply. I tried using that escaped value and it didn't work. I'm using a the script below in a dummy button which "clicks" a hidden submit button. So the script picks up a value of the name of one of the departments, which can have an ampersand, like "Advisory Board & Councils". So when the script runs I don't get an error (even with the debugger), it just chops everything that comes after that point in the script. When I click the Submit button that has the script below, everything after my form variable "Department" would just disappear.