Copy link to clipboard
Copied
Hi,
I am really new to javascript so bear with me. I am making a form where I have many checkboxes all named "checkbox 1" and so on (like 30 or more) that I have assigned export values (such as "red", "blue", "green"..etc). I need all of those checkboxes to populate their given export values to a single textbox(textbox 1) when checked and to remove the value when unchecked. also I need to have the values separated by commas when they are populated to the textbox and to be able to manually type in the text box as well. Please help
Use this code as the custom calculation script of your text field:
var values = [];
for (var i=1; i<=30; i++) {
var fname = "checkbox "+i;
var f = this.getField(fname);
if (f==null) {
console.println("Error! Can't find: " + fname);
continue;
}
if (f.valueAsString!="Off") values.push(f.valueAsString);
}
event.value = values.join(", ");
Copy link to clipboard
Copied
Use this code as the custom calculation script of your text field:
var values = [];
for (var i=1; i<=30; i++) {
var fname = "checkbox "+i;
var f = this.getField(fname);
if (f==null) {
console.println("Error! Can't find: " + fname);
continue;
}
if (f.valueAsString!="Off") values.push(f.valueAsString);
}
event.value = values.join(", ");
Copy link to clipboard
Copied
I also want to have a text box(Text4) to populate the same text box that check boxes populate to. How do I add that to the above script ?
Copy link to clipboard
Copied
I don't follow what you mean...
Copy link to clipboard
Copied
I have the checkboxes populating to "textbox 1" as discussed above. Now I want a textbox that I have named "textbox 4" to populate whatever I type in it to "textbox 1" as well. So in the end the checkboxes AND "textbox 4" will populate to "textbox 1".
Does that make sense?
Copy link to clipboard
Copied
Change the name of "textbox 4" to "textbox 1" and it will happen automatically.
Copy link to clipboard
Copied
That won't work because the check boxes that populate to "textbox 1" then populate to "textbox 4" if the textboxes have the same name and I don't want the check boxes to populate to both textboxes....Just "textbox 1"
Copy link to clipboard
Copied
But you want to copy the value from "textbox 1" to "textbox 4", right? So what's the difference?
Copy link to clipboard
Copied
Sorry, I understand now what you want to do.
Add this line before the last line of the previous code:
if (this.getField("textbox 4").valueAsString!="") values.push(this.getField("textbox 4").valueAsString);
Copy link to clipboard
Copied
It's still populating the checkbox values that are supposed to only go to "textbox 1" to "textbox 4". It's Literally just copying "textbox 1" and putting it into "textbox 4"
Copy link to clipboard
Copied
I just want what is typed into "textbox 4" to populate to "textbox 1" in addition to the checkboxes that already populate to "textbox 1"
Copy link to clipboard
Copied
I got it to work! thank you very much I appreciate it
Copy link to clipboard
Copied
I got it to work! Thanks!
Copy link to clipboard
Copied
In this example, instead of separating by a comma, how do I start a new text line for the next value?
Copy link to clipboard
Copied
Replace:
join(", ");
with:
join("\n");