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

Calculation Field Not Updating- Javascript Issue

Community Beginner ,
Aug 30, 2016 Aug 30, 2016

I have an Adobe Acrobat DC form with what I believe is a simple issue but has me stumped.  I have a field (InitialDate) in which the user inputs a date.  I have another field in which the user inputs the number of days (AddedDays) .  I want the third field FinalDate to calculate the value by adding the specified number of days from AddedDays to the InitialDate.  Below is the javascript I have added to under the calculate in the FinalDate field.

The javascript works great except when the user CHANGES the date in the InitialDate field, the FinalDate field is not updating.  If the user changes the AddedDays input, the FinalDate field is updating.  Can someone help me?

(function () {

var sDate = getField("InitialDate").valueAsString;

var d = util.scand("m/d/yy", sDate);

var days = getField("AddedDays").value;

d.setDate(d.getDate() + days);

if (sDate) {event.value = util.printd("m/d/yy", d);}

else {event.value = "No Transmission Date Entered";}

})();

TOPICS
Acrobat SDK and JavaScript
2.8K
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

correct answers 1 Correct answer

LEGEND , Aug 30, 2016 Aug 30, 2016

Yes, you need to correct the field calculation order as mentioned earlier. Exactly how you do this depends on which version of Acrobat you're using.

While you're in form editing mode, select:

Acrobat 9: Forms > Edit Fields > Set Field Calculation Order

Acrobat 10: Tasks > Other Tasks > Edit Fields > Set Field Calculation Order

Acrobat 11: Tasks > Other Tasks > Set Field Calculation Order

Acrobat DC: More (button in right-hand panel) > Set Field Calculation Order

Translate
LEGEND ,
Aug 30, 2016 Aug 30, 2016

Have you checked the JavaScript console (Ctrl+J) for any errors.

That one line should be:

var days = +getField("AddedDays").value;

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 ,
Aug 30, 2016 Aug 30, 2016

Also, check to make sure that the field calculation order is correct.

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 Beginner ,
Aug 30, 2016 Aug 30, 2016

So, I think I've found my issue which still has me confused.  For the purpose of simplification, I didn't actually explain my full scenario.  The "InitialDate" field is actually a calculated field itself from another field called "DateRequest".  So, the formula is trying to use a field that is a calculated field in and of itself.  Is there a way to order it so that all fields are immediately updated (like in a 'mouse up' event)? 

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 ,
Aug 30, 2016 Aug 30, 2016

Yes, you need to correct the field calculation order as mentioned earlier. Exactly how you do this depends on which version of Acrobat you're using.

While you're in form editing mode, select:

Acrobat 9: Forms > Edit Fields > Set Field Calculation Order

Acrobat 10: Tasks > Other Tasks > Edit Fields > Set Field Calculation Order

Acrobat 11: Tasks > Other Tasks > Set Field Calculation Order

Acrobat DC: More (button in right-hand panel) > Set Field Calculation Order

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 Beginner ,
Aug 31, 2016 Aug 31, 2016
LATEST

Field Calculation Order did the trick and it is working great now.  THANK YOU!!!! 

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