Run Calculation Script based on radio button choice
Copy link to clipboard
Copied
I have a fillable form and I currently run a calculation script to determine the date to depart a quarantine location on the 17th day of arrival. Since creating this form my company has added another location but this location the employee will depart on the 15th day of arrival. I want to use a set of radio buttons to determine how many days will be added to the arrival date to set the departure date. Below is my current script that adds 16 days to the arrival date.
var date= util.scand("dd-mmm-yyyy", this.getField("Leave End Date Field").value); date.setDate(date.getDate()+16) event.value=util.printd("dd-mmm-yyyy",date) if (getField("Leave End Date Field").value=="")event.value=""
I want a new script that will add either 16 days or 14 days depending on which radio button is checked. I’m guessing this will require an IF/Else statement but I’m not sure how to write it in combination with radio button choices.
I will appreciate all assistance anyone has to offer.
Copy link to clipboard
Copied
Lets say the radio buttons have a field name of "num_days_rb", and you set the export values of the two radio buttons to 14 and 16, the script could be modified to the following:
var date = util.scand("dd-mmm-yyyy", getField("Leave End Date Field").value);
if (getField("Leave End Date Field").valueAsString === "") {
event.value = "";
else {
var num_days = getField("num_days_rb").value;
date.setDate(date.getDate() + num_days);
event.value = util.printd("dd-mmm-yyyy", date);
}
This assumes one of the radio buttons is always selected. Otherwise, you'd have to account for neither radio button being selected (value = "Off"). It could use some refinement, but should get you started.
Copy link to clipboard
Copied
First of all, thank you for your reply. When I pasted the code in the Custom Calculation field of my Theater arrival date I received a syntax error.
Should I have pasted the code elsewhere?
Copy link to clipboard
Copied
Change this line:
else {
To:
} else {
Copy link to clipboard
Copied
That worked perfectly. Thank you so much.

