Copy link to clipboard
Copied
Hi there,
I know that there have been a lot of other thread like this one but for some reason my code isn't working. I'm trying to have text inserted into a field when a check box is checked. Can you please please help.
For a mouse up event:
var dateCheckbox = this.getField("Date or"); //checkbox
var detailField = this.getField("Expiration Detail"); //field
// if the "date or" box is checked than change the Expiration Detail to "Hello"
if (dateCheckbox.value == "Yes") {
detailField.value = "Hello";
}
1 Correct answer
Which mouse-up event are you using? In general, when you try to trigger something based on a checkbox selection, you should also take care of the unchecked value. Also, the export value of a checkbox can be modified, so it's usually a better approach to check for value != "Off", because "Off" will always be used for the unchecked case.
Try the following as the mouse-up event of the "Date or" checkbox:
...var detailField = this.getField("Expiration Detail"); //field
if (event.target.value != "Off")
Copy link to clipboard
Copied
Which mouse-up event are you using? In general, when you try to trigger something based on a checkbox selection, you should also take care of the unchecked value. Also, the export value of a checkbox can be modified, so it's usually a better approach to check for value != "Off", because "Off" will always be used for the unchecked case.
Try the following as the mouse-up event of the "Date or" checkbox:
var detailField = this.getField("Expiration Detail"); //field
if (event.target.value != "Off") {
detailField.value = "Hello";
}
else {
detailField.value = "";
}
Copy link to clipboard
Copied
That works perfectly!!!
Thank you so much for your time. I really appreciate it.
Copy link to clipboard
Copied
Hi Karl_Heinz_Kremer,
How can I used your scripting for multiple text fields? For example, if Checkbox1 is checked, Textfield1 and Textfield2 auto-populates "N/A"
Thank you in advance.
Copy link to clipboard
Copied
Use this as MouseUp event of CheckBox:
var t1 = this.getField("Textfield1");
var t2 = this.getField("Textfield2");
if(event.target.value != "Off"){
t1.value = "N/A"
t2.value = "N/A";}
else if(event.target.value == "Off"){
t1.value = ""
t2.value = "";}
Copy link to clipboard
Copied
Hi can any one help
If check box 'A' and checkbox 'B' both are checked then it should print value 'yes' else 'no'
Copy link to clipboard
Copied
As the custom calculation script of the text field enter this:
event.value = (this.getField("A").valueAsString=="Off" || this.getField("B").valueAsString=="Off") ? "no" : "yes";
Copy link to clipboard
Copied
What script would I use for the following:
Check box 1 = PDF
Check box 2 = Divorce Decree
Check box 3 = Birth Certificate
When all boxes are checked, the text is put into the same text box, or if only 2 boxes are checked, only the 2 texts are included in the text box.
Copy link to clipboard
Copied
Do you want to display the text in a single line? If so, should they be separated by something, like a comma or a semi-colon? Or should each text be on a separate line in a multi-line field?
Copy link to clipboard
Copied
Single line please!
Copy link to clipboard
Copied
You can use this code as the custom Calculation script of the final text field, then:
var fields = ["Check box 1", "Check box 2", "Check box 3"];
var texts = ["PDF", "Divorce Decree", "Birth Certificate"];
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
That worked perfectly! Thank you so much!
Copy link to clipboard
Copied
Another question...same thing, but I want some followed by a comma and some that I don't. Such as when Checkbox for "What was received" is toggled it adds "Rec'd" followed by no comma and then the others are selected which are followed by a comma.
Copy link to clipboard
Copied
@try67 please see my follow up question above! Thank you so much for the help!
Copy link to clipboard
Copied
Can you post the code, or the file?
Copy link to clipboard
Copied
This is what I currently have but I want some followed by just a space and some followed by a period:
var fields = ["CB37", "CB1", "CB2", "CB3", "CB4", "CB5", "CB6", "CB7", "CB8", "CB9", "CB10", "CB11", "CB12", "CB13", "CB14", "CB38", "CB15", "CB16", "CB17", "CB18", "CB19", "CB20", "CB21", "CB22", "CB23", "CB39", "CB24", "CB25", "CB27", "CB29", "CB30", "CB31", "CB32", "CB33", "CB42", "CB35"];
var texts = ["Rec'd", "PDF", "DD", "BC", "MC", "SSN Card", "ID", "Med ID", "Court Order", "Adoption Decree", "COB Docs", "DP Docs", "Kaiser EF", "COA", "FILL IN OTHER", "Updated", "Address", "Email", "Phone", "Name", "Gender", "Marital Status", "DOB", "Dep(s)", "FILL IN OTHER", "Mem", "Dep", "EIR sent for", "DD", "BC", "MC", "Adoption Decree", "FILL IN OTHER", "FILL IN OTHER LETTER SENT", "Doc(s) sent to scan"];
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
This description is a bit too vague. You need to clearly define which fields should be followed by a space, and which by a period. Maybe include it in the actual strings in the texts array, and change the delimiter under the join command to a blank string.
Copy link to clipboard
Copied
Can someone help me with google sheets

