Run Calculation Script based on radio button choice

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.

Consider this?

<!DOCTYPE html><html lang="en"><head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0, user-scalable=yes"/>
<title> Test Page </title>
<!-- For: https://www.sitepoint.com/community/t/run-calculation-script-based-on-radio-button-choice/361213 -->

</head><body>
<h1> Quarentine Calculator </h1>
Date entered int quarentine: <input type="date" id="startQuarentine" value=''>
<input type="radio" name='locations' value="14" onclick="showEndQuarentine(this)"> Location 1
<input type="radio" name='locations' value="16" onclick="showEndQuarentine(this)"> Location 2
<pre id='demo'></pre>
 
<script>
console.clear();

function showEndQuarentine(info) {
  const sdate = new Date(document.getElementById('startQuarentine').value);
  const inc = +info.value+1;  // +1 to get past this date
  let ndate = new Date(sdate.getFullYear(),sdate.getMonth(),sdate.getDate()+inc)
  document.getElementById('demo').innerHTML = ndate.toDateString();
}
</script>

</body></html>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.