How do I run script only if a certain cell is changed??

New Here ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

I have created a form with javascript that autofills  a date to the georgian calander. But everytime that you go to edit the pdf after the day it was orginally filled out it changes this date. How can I get it so that this only changes if a certain field is changed??? 

TOPICS
Standards and accessibility

Views

42

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
Adobe Community Professional ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

Use script as 'Validation' of that field.

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

Copy link to clipboard

Copied

sorry i'm new to this, would you be able to explain further. here is my current script 

 

var now = new Date();
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var oneDay = 1000 * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);

var textBox = this.getField("Text1");
textBox.value = day;
textBox.defaultValue = day;

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
Adobe Community Professional ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

LATEST

In field which you want to trigger script, go to properties -> Validation tab -> Run custom validation script and put script there. Script will only trigger if value of that field is changed. If you don't wan't to trigger script when you empty field use like this:

if(event.value){

//put script here, in between curly brackets

}

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
Adobe Community Professional ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

Two options:

- Move the code to that field's Validation event, or

- Add a condition to the Calculation script checking which field triggered it.

This can be done using event.source.name .

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