More efficient use of checkboxes and calculations.

Community Beginner ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

Hi all, I have prepared an interactive form that currently does what I want, but I am wondering if there is a more efficient way of  achieving the required actions.

 

The form is completed by an examiner when they have completed a competency test with a trainee. It then prints out as a certificate for the trainee to keep in their records. There are a number of competencies that can be assesed; some valid for six months, some for a year, and some for two years. My form has a series of checkboxes that the examiner can select to denote what was covered in the assessment, as well as a field to enter the date of the assessment. From this information the form populates fields for the due dates of the next competency assessments in each category.

 

For each of the 'due date' fields I have used JavaScript to calculate the forward date if the related checkbox is selected, and the date of the assessment has been entered. My issue was that if the examiner changed their mind and unselected one of the checkboxes, the related due date field remained populated with the forward date.

 

I countered this by adding an Action on each checkbox to run essentially the same JavaScript clause to populate the due date field if a date has been entered, or clear the due date field if the checkcox is deselected.

 

So I am wondering if there is a way to achieve this without the duplication? Can a field be set to automatically recalculate if any related fileds are altered?

 

Here is an example of the JS for one of the checkboxes:

var cDate = this.getField("Examination_Date").value;
var cBFR = this.getField("BFR_check").value;
if (cDate && cBFR=="Yes") {
    var d1 = new Date();
    d1 = util.scand("dd/mm/yy", cDate);
    d1.setFullYear(d1.getFullYear() + 2); // this adds two years
    this.getField("BFR_due_date").value = util.printd("dd/mm/yy", d1);
    }
else {
    this.getField("BFR_due_date").value = "";
}

Interested in any approaches to this.

 

Many thanks for any information provided.

TOPICS
How to , JavaScript , PDF forms

Views

48

Likes

Translate

Translate

Report

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

correct answers 1 Correct answer

Adobe Community Professional , May 16, 2022 May 16, 2022
The answer is very simple: remove all the scripts from the checkboxes and place the script only once as a calculation script in a Text field (in the "BFR_due_date" field for example). A calculation script is triggered by any user action on any field in the document.

Likes

Translate

Translate
Adobe Community Professional ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

The answer is very simple: remove all the scripts from the checkboxes and place the script only once as a calculation script in a Text field (in the "BFR_due_date" field for example).
A calculation script is triggered by any user action on any field in the document.

Likes

Translate

Translate

Report

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 Beginner ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

LATEST

Doh!

When I first set the script for the text fields I did not incorporate the 'else' clause to clear the value, but I did add that for the checkboxes.

 

I have done as you suggested set the script as I posted for the text fields and it is all as I wanted, thanks JR.

Likes

Translate

Translate

Report

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