Copy link to clipboard
Copied
Hi all,
Creating a new string because I still need help. I need words to be produced in a text box when check boxes are toggled. Some I need followed by a comma, some just by a space. Below is an example of my form, followed by my current code.
If every one of the above are checked it should produce "Rec'd PDF, DD, BC". Obviously, this code is not working, but I don't know how to fix it.
var fields = ["CB1"];
var texts = ["Rec’d"];
var selectedTexts = [];
for (var i=0; i<fields.length; i++) {
if (this.getField(fields[i].valueAsString!="Off")) selectedTexts.push(texts[i]);
}
event.value = selectedTexts.join(" ");
var fields = ["CB2", "CB3", "CB4"];
var texts = ["PDF", "DD", "BC"];
var selectedTexts = [];
for (var i=0; i<fields.length; i++ {
if (this.getField(fields[i].valueAsString!="Off")) selectedTexts.push(texts [i]);
{
event.value = selectedTexts.join(", ");
Copy link to clipboard
Copied
What is not working?
Info: The second part of your script overrides the result of the first part.
Copy link to clipboard
Copied
Well currently the entire thing is not working. Which is why I am asking for help.
Copy link to clipboard
Copied
Check the Javascript console for errors.
Copy link to clipboard
Copied
The script doesn't look bad. But there are a couple of obvious issues.
#1 The last "if" is missing both the closing ")" and the closing "}"
#2 The second "event.value =" is overriding the first one. It would be better to create a string variable to accumulate the string values. Then set "event.value" at the end.
Another suggestion. Set the checkbox export values to the output string value. Then the script can just concatonate the export values.