Copy link to clipboard
Copied
I am working on adding text to a text box when multiple checkboxes are marked/selected. I have looked all through the links that have been sent to me and tried several suggested options, but nothing is working for me. (this is why I do not make my living as a code specialist!)
I need for these boxes outlined in Red :
to add text to this box below all at the same time if the box is checked..
I will be doing this same thing from drop down boxes once I have this part with the checkmarks completed.
Thanks in advance for any assistance for this newbie!
Copy link to clipboard
Copied
You can use something like this as custom calculation script of text field where you want to show text:
var c1 = this.getField("Check Box1").valueAsString;
var c2 = this.getField("Check Box2").valueAsString;
var c3 = this.getField("Check Box3").valueAsString;
//Use your actual names for the checkboxes
if(c1 !== "Off" && c2 !== "Off" && c3 !== "Off")
event.value = "Some text";
else
event.value = "";//set event.value to desired value when chekboxes are not checked
Copy link to clipboard
Copied
Thank-you so much!
In this line..........
set event.value to desired value when chekboxes are not checked
Is this where I type the text that I want to be placed in this text box? The text for each checkbox is different; do I add all 3 options in this spot?
Copy link to clipboard
Copied
event.value = "" means if no conditions are met field will be empty, instead of set field to be empty you can set it to some other default text if you need, if not than leave as it is.
Where it says "Some text" that is where you input your text to show in the field.
If you have multiple text, use 'else if' conditions for each text.
Copy link to clipboard
Copied
Thank-you very much Nesa!
I have applied the code that you provided and I think I am missing something since I cannot close the java script box and I hear a dinging sound with a highlight that something is wrong. No matter what I "fix", I can't get past it.
I think I am going in the right direction, but this is what I have, can you help me tweek it appropriately?? I am working with 3 different checkboxes at the moment, each should populate its own text. 🙂
var c1 = this.getField("Completed Operations").valueAsString;
var c2 = this.getField("Primary Non-Contributory").valueAsString;
var c3 = this.getField("30 Day Cancellation").valueAsString;
//Use your actual names for the checkboxes
if(c1 !== "Off" && c2 !== "Off" && c3 !== "Off")
event.value = "Certificate holder is an Additional Insured and will provide Ongoing & Completed Operations Coverage in accordance with policy language, when under contract with insured, relating to general liability.";
else if = "Coverage extended to the scheduled Additional Insured, as afforded in the Comprehensive General Liability coverage, is provided on a primary, noncontributory, or excess basis only as defined in the policy language."
else if = "We will endeavor to mail written notice of cancellation at least ten (10) days before the date of cancellation if we cancel for non-payment of premium, thirty (30) days before the cancellation date if we cancel for any other reason, as provided in policy language."
else
event.value = "";//set event.value to desired value when chekboxes are not checked
Copy link to clipboard
Copied
You are missing condition for both 'else if'.
var c1 = this.getField("Completed Operations").valueAsString;
var c2 = this.getField("Primary Non-Contributory").valueAsString;
var c3 = this.getField("30 Day Cancellation").valueAsString;
if(c1 !== "Off" && c2 !== "Off" && c3 !== "Off")//this is 1st condition: all 3 checkboxes needs to be checked
event.value = "Certificate holder is an Additional Insured and will provide Ongoing & Completed Operations Coverage in accordance with policy language, when under contract with insured, relating to general liability.";
else if(Replace this text with 2nd condition)
event.value = "Coverage extended to the scheduled Additional Insured, as afforded in the Comprehensive General Liability coverage, is provided on a primary, noncontributory, or excess basis only as defined in the policy language.";
else if(Replace this text with 3rd condition)
event.value = "We will endeavor to mail written notice of cancellation at least ten (10) days before the date of cancellation if we cancel for non-payment of premium, thirty (30) days before the cancellation date if we cancel for any other reason, as provided in policy language.";
else
event.value = "";
Copy link to clipboard
Copied
Hello i use the same script but with
i can make the text show when one condtion is true or all 6
but if i choose checkbox 1, or 2 or 3 or 4 , checkbox's it wont show the text other than the first but
my script goes like this:
var c1 = this.getField("CheckF").valueAsString;
var c2 = this.getField("CheckEL").valueAsString;
var c3 = this.getField("CheckS").valueAsString;
var c4 = this.getField("CheckT").valueAsString;
var c5 = this.getField("CheckE").valueAsString;
var c6 = this.getField("CheckR").valueAsString;
if(c1 !== "Off" && c2 !== "Off" && c3 != "Off" && c4 !== "Off" && c5 != "Off" && c6 !== "Off") {
event.value = "Fastestoffer 10m,Væsker 50m,Gasudslip 100m,\nFordråbet Gas 300m\nSikkerheds mht RØR,Spredt stråle 5m samlet stråle 15m,\n300m eller 10m bag betonvæg eller stort køretøj,\nSKAF anvendes,Sikkerhedsafstand 1000M,Radioaktivitet";
}
else if(c1 !== "Off"){
event.value="Fastestoffer 10m,Væsker 50m,Gasudslip 100m,\nFordråbet Gas 300m";
}
else if(c1 !== "Off" && c2 !== "Off"){
event.value = "Fastestoffer 10m,Væsker 50m,Gasudslip 100m,\nFordråbet Gas 300m\nSikkerheds mht RØR,Spredt stråle 5m samlet stråle 15m";
}
else if (c2 !== "Off") {
event.value = "Sikkerheds mht RØR,Spredt stråle 5m samlet stråle 15m ";
}
else if(c1 !== "Off" && c2 !== "Off" && c3 !== "Off"){
event.value = "Fastestoffer 10m,Væsker 50m,Gasudslip 100m,\nFordråbet Gas 300m\nSikkerheds mht RØR,Spredt stråle 5m samlet stråle 15m,\nSKAF anvendes";
}
else if (c3 !== "Off") {
event.value = "SKAF anvendes";
}
else if(c1 !== "Off" && c2 !== "Off" && c3 !== "Off" && c4 !== "Off"){
event.value = "Fastestoffer 10m,Væsker 50m,Gasudslip 100m,\nFordråbet Gas 300m\nSikkerheds mht RØR,Spredt stråle 5m samlet stråle 15m,\nSKAF anvendes,\n300m eller 10m bag betonvæg eller stort køretøj";
}
else if (c4 !== "Off") {
event.value = "300m eller 10m bag betonvæg eller stort køretøj";
}
else if(c1 !== "Off" && c2 !== "Off" && c3 !== "Off" && c4 !== "Off" && c5 !== "Off"){
event.value = "Fastestoffer 10m,Væsker 50m,Gasudslip 100m,\nFordråbet Gas 300m\nSikkerheds mht RØR,Spredt stråle 5m samlet stråle 15m,\nSKAF anvendes,\n300m eller 10m bag betonvæg eller stort køretøj,Sikkerhedsafstand 1000M";
}
else if (c5 !== "Off"){
event.value = "Sikkerhedsafstand 1000M";
}
else if (c6 !== "Off"){
event.value = "Radioaktivitet";
}
else {
event.value = "";
}
so if one checkbox is chosen or one combination of the chosen checkbox the i would like to show the text
i am not quit finish with the script but i know i have to make a lot else if but testing as i go along with coding
Copy link to clipboard
Copied
A much better solution is to populate an array with the text for each check-box, and then join the values in the array to a single string. The way you're doing it now will require you to cover every possible combination, and there are a LOT of those.
Copy link to clipboard
Copied
I have tried that with and array but can't quit figure out the script something goes wrong. I have been looking for samples on the adobe coomunity to find somthing I could use and build from that but i keep learning new things when i find something i can use
do you have a link on how to make scripts for arrays
Copy link to clipboard
Copied
Try this code (adjust the texts as needed, of course):
var c1 = this.getField("CheckF").valueAsString;
var c2 = this.getField("CheckEL").valueAsString;
var c3 = this.getField("CheckS").valueAsString;
var c4 = this.getField("CheckT").valueAsString;
var c5 = this.getField("CheckE").valueAsString;
var c6 = this.getField("CheckR").valueAsString;
var texts = [];
if (c1!="Off") texts.push("Text for C1");
if (c2!="Off") texts.push("Text for C2");
if (c3!="Off") texts.push("Text for C3");
if (c4!="Off") texts.push("Text for C4");
if (c5!="Off") texts.push("Text for C5");
if (c6!="Off") texts.push("Text for C6");
event.value = texts.join(", ");