Reset Text FIeld when Date is changed

Contributor ,
Sep 22, 2017

Copy link to clipboard

Copied

Hello,

I am making a form in Adobe Acrobat Pro  in which i want to reset a Text Field to value 1 whenever the Date is changed.

I have two Text Field  :  

Text1 = Date field this field auto-populates the current date when the file is opened

Text2 - this field has to be reset to "1"  every time the date is changed.

Like if the form is opened today  eg. 23/09/2017 ... i can enter any number in Text2 and save it................. but if the file is opened next day..... Text2 should be reset to 1 then on 24/09/2017 i can enter any number in text2  and save it..... but when again on 25/09/2017 if i open the file text 2 should be reset to "1".

Thanks in advance.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Use this:

this.getField("Text2").value = Number(this.getField("Text2").value)+1;

TOPICS
Acrobat SDK and JavaScript, Windows

Views

398

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

Reset Text FIeld when Date is changed

Contributor ,
Sep 22, 2017

Copy link to clipboard

Copied

Hello,

I am making a form in Adobe Acrobat Pro  in which i want to reset a Text Field to value 1 whenever the Date is changed.

I have two Text Field  :  

Text1 = Date field this field auto-populates the current date when the file is opened

Text2 - this field has to be reset to "1"  every time the date is changed.

Like if the form is opened today  eg. 23/09/2017 ... i can enter any number in Text2 and save it................. but if the file is opened next day..... Text2 should be reset to 1 then on 24/09/2017 i can enter any number in text2  and save it..... but when again on 25/09/2017 if i open the file text 2 should be reset to "1".

Thanks in advance.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Use this:

this.getField("Text2").value = Number(this.getField("Text2").value)+1;

TOPICS
Acrobat SDK and JavaScript, Windows

Views

399

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
Sep 22, 2017 0
Most Valuable Participant ,
Sep 23, 2017

Copy link to clipboard

Copied

Post the code you used for Text1.

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
Reply
Loading...
Sep 23, 2017 0
Contributor ,
Sep 23, 2017

Copy link to clipboard

Copied

I used the following script to auto-populate the Text1 (current date) with the help of a button :

this.getField("Text1").value = util.printd("yymmdd", new Date();

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
Reply
Loading...
Sep 23, 2017 0
Most Valuable Participant ,
Sep 23, 2017

Copy link to clipboard

Copied

OK. Use this code instead:

var currentValue = this.getField("Text1").valueAsString;

var newValue = util.printd("yymmdd", new Date());

if (currentValue!=newValue) this.getField("Text2").value = "1";

this.getField("Text1").value = newValue;

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
Reply
Loading...
Sep 23, 2017 0
Contributor ,
Sep 23, 2017

Copy link to clipboard

Copied

Thank you sir....

Your script worked absolutely as the way i wanted...................

I put the script in the button1.

i stuck in other problem ........ i want the Text 2 to get incremented if i click the button in the same date...

Like if i open the file today and click the button . text1  = today date and Text2 = 1 .. i saved it ...... and closed the form..... now after few hours i want to open the file again... and this time if i click the button (on the same date)   Text 1 = today date and Text 2 = 2 and so on..........

I modified your script to the following but it doesnot seem to work

var currentValue = this.getField("Text1").valueAsString; 

var newValue = util.printd("yymmdd", new Date()); 

if (currentValue!=newValue)

{this.getField("Text2").value = "1"; 

this.getField("Text1").value = newValue;}

else {

this.info.ID = 1;

this.getField("Text2").value = this.info.ID++;

}

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
Reply
Loading...
Sep 23, 2017 0
Most Valuable Participant ,
Sep 23, 2017

Copy link to clipboard

Copied

If you use the script I provided as a doc-level script it will work just

the same as from your button.

On Sat, Sep 23, 2017 at 12:55 PM, rakeshk21205956 <forums_noreply@adobe.com>

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
Reply
Loading...
Sep 23, 2017 0
Contributor ,
Sep 23, 2017

Copy link to clipboard

Copied

Thank you sir....

Your script worked absolutely as the way i wanted...................

I put the script in the button1.

i stuck in other problem ........ i want the Text 2 to get incremented if i click the button in the same date...

Like if i open the file today and click the button . text1  = today date and Text2 = 1 .. i saved it ...... and closed the form..... now after few hours i want to open the file again... and this time if i click the button (on the same date)   Text 1 = today date and Text 2 = 2 and so on..........

I modified your script to the following but it doesnot seem to work

var currentValue = this.getField("Text1").valueAsString; 

var newValue = util.printd("yymmdd", new Date()); 

if (currentValue!=newValue)

{this.getField("Text2").value = "1"; 

this.getField("Text1").value = newValue;}

else {

this.info.ID = 1;

this.getField("Text2").value = this.info.ID++;

}

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
Reply
Loading...
Sep 23, 2017 0
Most Valuable Participant ,
Sep 23, 2017

Copy link to clipboard

Copied

Use this:

this.getField("Text2").value = Number(this.getField("Text2").value)+1;

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
Reply
Loading...
Sep 23, 2017 0
Contributor ,
Sep 23, 2017

Copy link to clipboard

Copied

Thank you very much... worked perfectly..............Thanks a lot..........

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
Reply
Loading...
Sep 23, 2017 0