Coding validation to have text box fill when box is checked
Copy link to clipboard
Copied
Hi there! Hoping you can assist me. I have four check boxes in a form that should each populate specific text into the text box below. There will be scenarios where more than one box is checked, so the text box should be able to populate each checked box's text individually and in combination with other boxes. Through use of this community and Youtube, I've been able to create codes to have it populate when two boxes are checked, but when just one box is checked, nothing populates. I have not yet moved on to when three or all four boxes are checked due to this issue. I believe I can code for three and four, but for some reason am unable to have the text populate when clicking only one. I have attached the document (which includes the code that I've input so far) and hope you can help!
Copy link to clipboard
Copied
For each condition, you have combinations of two checkboxes, for example for first condition you have b1&&b2 which means b1 and b2 needs to be checked, but if you wish to show other combinations too you need to concatenate text, the easiest way would be to assign text to checkbox or combinations of checkboxes.
If you let us know all the combinations, we may be able to help you with a script.
EDIT:
If those are all the conditions you wish to use but you want to show all conditions that are true you can use this script:
var b1 = this.getField("Check Box2").isBoxChecked(0);
var b2 = this.getField("Check Box3").isBoxChecked(0);
var b3 = this.getField("Check Box4").isBoxChecked(0);
var b4 = this.getField("Check Box5").isBoxChecked(0);
var str = [];
if(b1&&b2)
str.push("Brief FBA - The purpose of the brief FBA is to identify the function(s) of a student’s maladaptive or problematic behavior. Once the functions of the behavior(s) are identified, replacement behaviors and interventions can be identified that share the function as the maladaptive or problematic behavior. Behavior Incentive Plan - A behavior incentive plan is a structured program designed to motivate students to exhibit desired behaviors by offering rewards or positive reinforcements. The plan involves identifying specific behaviors that contribute to overall goals or objectives and then establishing a system of rewards for the student when they demonstrate those behaviors. The aim is to create a positive and motivating environment that encourages individuals to consistently engage in behaviors that contribute to the success of an organization or the achievement of personal and professional objectives.");
if(b1&&b3)
str.push("Brief FBA - The purpose of the brief FBA is to identify the function(s) of a student’s maladaptive or problematic behavior. Once the functions of the behavior(s) are identified, replacement behaviors and interventions can be identified that share the function as the maladaptive or problematic behavior. Attendance Contracts - Attendance contracts are agreements between the student, the school and the parent/guardian that identify clear goals for improving attendance and provide agreed upon consequences and incentives identified within the contract term.");
if(b1&&b4)
str.push("Brief FBA - The purpose of the brief FBA is to identify the function(s) of a student’s maladaptive or problematic behavior. Once the functions of the behavior(s) are identified, replacement behaviors and interventions can be identified that share the function as the maladaptive or problematic behavior. Personal Check-In- Short and short-term check-ins with a mental health staff member (i.e., school counselor, school adjustment counselor, school psychologist, etc.). Note: This is not individual counseling. It is not goal-directed. It is more frequent, scheduled, check-ins with students for the purpose of increasing their connectedness to a trusted adult at school and to monitor their social-emotional wellbeing.");
if(b2&&b3)
str.push("Behavior Incentive Plan - A behavior incentive plan is a structured program designed to motivate students to exhibit desired behaviors by offering rewards or positive reinforcements. The plan involves identifying specific behaviors that contribute to overall goals or objectives and then establishing a system of rewards for the student when they demonstrate those behaviors. The aim is to create a positive and motivating environment that encourages individuals to consistently engage in behaviors that contribute to the success of an organization or the achievement of personal and professional objectives. Attendance Contracts - Attendance contracts are agreements between the student, the school and the parent/guardian that identify clear goals for improving attendance and provide agreed upon consequences and incentives identified within the contract term.");
if(b2&&b4)
str.push("Behavior Incentive Plan - A behavior incentive plan is a structured program designed to motivate students to exhibit desired behaviors by offering rewards or positive reinforcements. The plan involves identifying specific behaviors that contribute to overall goals or objectives and then establishing a system of rewards for the student when they demonstrate those behaviors. The aim is to create a positive and motivating environment that encourages individuals to consistently engage in behaviors that contribute to the success of an organization or the achievement of personal and professional objectives. Personal Check-In- Short and short-term check-ins with a mental health staff member (i.e., school counselor, school adjustment counselor, school psychologist, etc.). Note: This is not individual counseling. It is not goal-directed. It is more frequent, scheduled, check-ins with students for the purpose of increasing their connectedness to a trusted adult at school and to monitor their social-emotional wellbeing.") ;
if(b3&&b4)
str.push("Attendance Contracts - Attendance contracts are agreements between the student, the school and the parent/guardian that identify clear goals for improving attendance and provide agreed upon consequences and incentives identified within the contract term. Personal Check-In- Short and short-term check-ins with a mental health staff member (i.e., school counselor, school adjustment counselor, school psychologist, etc.). Note: This is not individual counseling. It is not goal-directed. It is more frequent, scheduled, check-ins with students for the purpose of increasing their connectedness to a trusted adult at school and to monitor their social-emotional wellbeing.") ;
if(str.length == 0)
event.value = "";
else
event.value = str.join("\n\n");
Copy link to clipboard
Copied
Unfortunately, this solution is not allowing each box to be checked individually.
If you consider that each checkbox connects to one section of text (ie. Check Box 2 being checked should populate the section of text labeled "Brief FBA" only, Check Box 3 being checked should populate the section of text labeled "Behavior Incentive Plan" only, and so on), the issue is that the solution given only accounts for the variations. When you check two boxes, it pulls up those two fields of text, but when you check a third box, it pulls up the first two sections of text twice and then the third section of text. This code still does not solve the original issue of allowing for a single check box to populate the appropriate text.
For reference:
CheckBox 2 text: Brief FBA - The purpose of the brief FBA is to identify the function(s) of a student’s maladaptive or problematic behavior. Once the functions of the behavior(s) are identified, replacement behaviors and interventions can be identified that share the function as the maladaptive or problematic behavior.
CheckBox 3 text: Behavior Incentive Plan - A behavior incentive plan is a structured program designed to motivate students to exhibit desired behaviors by offering rewards or positive reinforcements. The plan involves identifying specific behaviors that contribute to overall goals or objectives and then establishing a system of rewards for the student when they demonstrate those behaviors. The aim is to create a positive and motivating environment that encourages individuals to consistently engage in behaviors that contribute to the success of an organization or the achievement of personal and professional objectives.
CheckBox 4 text: Attendance Contracts - Attendance contracts are agreements between the student, the school and the parent/guardian that identify clear goals for improving attendance and provide agreed upon consequences and incentives identified within the contract term.
CheckBox 5 text: Personal Check-In - Short and short-term check-ins with a mental health staff member (i.e., school counselor, school adjustment counselor, school psychologist, etc.). Note: This is not individual counseling. It is not goal-directed. It is more frequent, scheduled, check-ins with students for the purpose of increasing their connectedness to a trusted adult at school and to monitor their social-emotional wellbeing.
Copy link to clipboard
Copied
So you want only single checkboxes text or variations also?
Copy link to clipboard
Copied
Use this:
var c2 = this.getField("Check Box2").isBoxChecked(0);
var c3 = this.getField("Check Box3").isBoxChecked(0);
var c4 = this.getField("Check Box4").isBoxChecked(0);
var c5 = this.getField("Check Box5").isBoxChecked(0);
var str = [];
if(c2)
str.push("Brief FBA - The purpose of the brief FBA is to identify the function(s) of a student’s maladaptive or problematic behavior. Once the functions of the behavior(s) are identified, replacement behaviors and interventions can be identified that share the function as the maladaptive or problematic behavior.");
if(c3)
str.push("Behavior Incentive Plan - A behavior incentive plan is a structured program designed to motivate students to exhibit desired behaviors by offering rewards or positive reinforcements. The plan involves identifying specific behaviors that contribute to overall goals or objectives and then establishing a system of rewards for the student when they demonstrate those behaviors. The aim is to create a positive and motivating environment that encourages individuals to consistently engage in behaviors that contribute to the success of an organization or the achievement of personal and professional objectives.");
if(c4)
str.push("Attendance Contracts - Attendance contracts are agreements between the student, the school and the parent/guardian that identify clear goals for improving attendance and provide agreed upon consequences and incentives identified within the contract term.");
if(c5)
str.push("Personal Check-In - Short and short-term check-ins with a mental health staff member (i.e., school counselor, school adjustment counselor, school psychologist, etc.). Note: This is not individual counseling. It is not goal-directed. It is more frequent, scheduled, check-ins with students for the purpose of increasing their connectedness to a trusted adult at school and to monitor their social-emotional wellbeing.");
if(str.length == 0)
event.value = "";
else
event.value = str.join("");
Copy link to clipboard
Copied
This worked perfectly!
Thank you!
Copy link to clipboard
Copied
Use this code:
var b1 = this.getField("Check Box2").isBoxChecked(0);
var b2 = this.getField("Check Box3").isBoxChecked(0);
var b3 = this.getField("Check Box4").isBoxChecked(0);
var b4 = this.getField("Check Box5").isBoxChecked(0);
var texts = []
if(b1&&b2)
texts.push("Brief FBA - The purpose of the brief FBA is to identify the function(s) of a student’s maladaptive or problematic behavior. Once the functions of the behavior(s) are identified, replacement behaviors and interventions can be identified that share the function as the maladaptive or problematic behavior. Behavior Incentive Plan - A behavior incentive plan is a structured program designed to motivate students to exhibit desired behaviors by offering rewards or positive reinforcements. The plan involves identifying specific behaviors that contribute to overall goals or objectives and then establishing a system of rewards for the student when they demonstrate those behaviors. The aim is to create a positive and motivating environment that encourages individuals to consistently engage in behaviors that contribute to the success of an organization or the achievement of personal and professional objectives.");
if(b1&&b3)
texts.push("Brief FBA - The purpose of the brief FBA is to identify the function(s) of a student’s maladaptive or problematic behavior. Once the functions of the behavior(s) are identified, replacement behaviors and interventions can be identified that share the function as the maladaptive or problematic behavior. Attendance Contracts - Attendance contracts are agreements between the student, the school and the parent/guardian that identify clear goals for improving attendance and provide agreed upon consequences and incentives identified within the contract term.");
if(b1&&b4)
texts.push("Brief FBA - The purpose of the brief FBA is to identify the function(s) of a student’s maladaptive or problematic behavior. Once the functions of the behavior(s) are identified, replacement behaviors and interventions can be identified that share the function as the maladaptive or problematic behavior. Personal Check-In- Short and short-term check-ins with a mental health staff member (i.e., school counselor, school adjustment counselor, school psychologist, etc.). Note: This is not individual counseling. It is not goal-directed. It is more frequent, scheduled, check-ins with students for the purpose of increasing their connectedness to a trusted adult at school and to monitor their social-emotional wellbeing.");
if(b2&&b3)
texts.push("Behavior Incentive Plan - A behavior incentive plan is a structured program designed to motivate students to exhibit desired behaviors by offering rewards or positive reinforcements. The plan involves identifying specific behaviors that contribute to overall goals or objectives and then establishing a system of rewards for the student when they demonstrate those behaviors. The aim is to create a positive and motivating environment that encourages individuals to consistently engage in behaviors that contribute to the success of an organization or the achievement of personal and professional objectives. Attendance Contracts - Attendance contracts are agreements between the student, the school and the parent/guardian that identify clear goals for improving attendance and provide agreed upon consequences and incentives identified within the contract term.");
if(b2&&b4)
texts.push("Behavior Incentive Plan - A behavior incentive plan is a structured program designed to motivate students to exhibit desired behaviors by offering rewards or positive reinforcements. The plan involves identifying specific behaviors that contribute to overall goals or objectives and then establishing a system of rewards for the student when they demonstrate those behaviors. The aim is to create a positive and motivating environment that encourages individuals to consistently engage in behaviors that contribute to the success of an organization or the achievement of personal and professional objectives. Personal Check-In- Short and short-term check-ins with a mental health staff member (i.e., school counselor, school adjustment counselor, school psychologist, etc.). Note: This is not individual counseling. It is not goal-directed. It is more frequent, scheduled, check-ins with students for the purpose of increasing their connectedness to a trusted adult at school and to monitor their social-emotional wellbeing.");
if(b3&&b4)
texts.push("Attendance Contracts - Attendance contracts are agreements between the student, the school and the parent/guardian that identify clear goals for improving attendance and provide agreed upon consequences and incentives identified within the contract term. Personal Check-In- Short and short-term check-ins with a mental health staff member (i.e., school counselor, school adjustment counselor, school psychologist, etc.). Note: This is not individual counseling. It is not goal-directed. It is more frequent, scheduled, check-ins with students for the purpose of increasing their connectedness to a trusted adult at school and to monitor their social-emotional wellbeing.");
event.value = texts.join("\n");
Copy link to clipboard
Copied
Oops, I see you already got an answer...

