Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Run Calculation Script based on radio button choice

New Here ,
Dec 21, 2020 Dec 21, 2020

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.

TOPICS
JavaScript , PDF forms
692
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 21, 2020 Dec 21, 2020

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 22, 2020 Dec 22, 2020

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.

RB_Error.JPGexpand image

RB.JPGexpand imageRB_14.JPGexpand imageRB_16.JPGexpand image

Should I have pasted the code elsewhere?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 22, 2020 Dec 22, 2020

Change this line:

else {

To:

} else {

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 22, 2020 Dec 22, 2020
LATEST

That worked perfectly.  Thank you so much.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines