How to Store the Old Date into Variable and Call it again

Engaged ,
Apr 28, 2018 Apr 28, 2018

Copy link to clipboard

Copied

Hi Experts..

I write code in checkbox so when clicked it will show (today date) inside date field, the problem is that i want when the user uncheck the Checked box it will restore again the old date, i try to store the date many ways but the script is ignoring any variable to store the old date,, so it ends me to call the old date from another field,, but are there any way straight forward in the same code , here is my code inside ( MouseUp Event of the Checkbox) :

// Write Today Date in Georgian

//WriteTodayDate if Checked

// box is checked

if (event.target.value != "Off") {

// get todays date object

var oNow = new Date();

var sNow = util.printd("yyyy/mm/dd", oNow);

// set date now

this.getField("todaysDate").value = sNow;

} else {

// box is unchecked

//Set the Old date

var OrgDate = this.getField("PrevDate").value;

this.getField("todaysDate").value = OrgDate;

}

and Thanks in Advance for any help

Best
M.Hasanain
TOPICS
Acrobat SDK and JavaScript, Windows

Views

654

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 , Apr 30, 2018 Apr 30, 2018
Try this:if (event.target.value != "Off") {    // save the Old date  this.getField("PrevDate").value = this.getField("todaysDate").value;// get todays date object  var oNow = new Date();  var sNow = util.printd("yyyy/mm/dd", oNow);  // set date now  this.getField("todaysDate").value = sNow;    } else {  // box is unchecked  //Set the Old date  var OrgDate = this.getField("PrevDate").value;  this.getField("todaysDate").value = OrgDate;    } 

Likes

Translate

Translate
Engaged ,
Apr 28, 2018 Apr 28, 2018

Copy link to clipboard

Copied

also i tried to re-write the code as the following but it also not working...it write only the new date but never restore the old date

// Write Today Date in Georgian

//WriteTodayDate if Checked

// convert a date or time string to a date object;

var cDateFormat = "yyyy/mm/dd"; // format for date string;

// open date values;

var cOpenDate = this.getField("todaysDate").value;

// box is checked

if (event.target.value != "Off") {

// Today date values;

var cTodayDate = new Date();

var oCloseDate = util.printd("yyyy/mm/dd", cTodayDate);

this.getField("todaysDate").value = oCloseDate

} else {

// box is unchecked

//Set the Old date

var oOpenDate = Scand(cDateFormat, cOpenDate);

this.getField("todaysDate").value = oOpenDate

}

Best
M.Hasanain

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 ,
Apr 29, 2018 Apr 29, 2018

Copy link to clipboard

Copied

Where did you set the value of the field "PrevDate"?

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
Engaged ,
Apr 29, 2018 Apr 29, 2018

Copy link to clipboard

Copied

I duplicate the DateField (TodaysDate) and Named it (PrevDate) then i put (On Blur) action in (TodaysDate) javascript it to Give The (PrevDate) its Value :

this.getField("PrevDate").value = event.value;

This  Method Works and Everything is fine,, but i forced to Hide (PrevDate) Field, i Was Wondering if there is a Straight Forward Way in One Script

Best
M.Hasanain

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 ,
Apr 29, 2018 Apr 29, 2018

Copy link to clipboard

Copied

In the properties of the field you can set it as hidden.

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
Engaged ,
Apr 29, 2018 Apr 29, 2018

Copy link to clipboard

Copied

yes i do that, but i wondering, are this the best solution ?

Best
M.Hasanain

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 ,
Apr 29, 2018 Apr 29, 2018

Copy link to clipboard

Copied

No. What kind of old date want you?

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
Engaged ,
Apr 29, 2018 Apr 29, 2018

Copy link to clipboard

Copied

old date simply is the re written date in the field before hitting the checkbox

Best
M.Hasanain

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 ,
Apr 29, 2018 Apr 29, 2018

Copy link to clipboard

Copied

Save the value before you change value of this 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
Engaged ,
Apr 29, 2018 Apr 29, 2018

Copy link to clipboard

Copied

i try to save it in the same checkbox code but no success ,, but did you mean to save it inside the field of the Date ?

Best
M.Hasanain

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 ,
Apr 30, 2018 Apr 30, 2018

Copy link to clipboard

Copied

What code do you use?

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
Engaged ,
Apr 30, 2018 Apr 30, 2018

Copy link to clipboard

Copied

i Used this Code ... i think my problem that i tried to save the variable in the same time to hit checkbox and this is not possible to store the old date / Pre Written Date.

  1. // Write Today Date in Georgian 
  2. //WriteTodayDate if Checked 
  3. // convert a date or time string to a date object; 
  4. var cDateFormat = "yyyy/mm/dd"; // format for date string; 
  5. // open date values; 
  6. var cOpenDate = this.getField("todaysDate").value; 
  7.  
  8. // box is checked 
  9. if (event.target.value != "Off") { 
  10.  
  11. // Today date values; 
  12. var cTodayDate = new Date(); 
  13. var oCloseDate = util.printd("yyyy/mm/dd", cTodayDate); 
  14. this.getField("todaysDate").value = oCloseDate  
  15.  
  16. } else
  17. // box is unchecked 
  18. //Set the Old date 
  19. var oOpenDate = Scand(cDateFormat, cOpenDate); 
  20. this.getField("todaysDate").value = oOpenDate 
Best
M.Hasanain

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 ,
Apr 30, 2018 Apr 30, 2018

Copy link to clipboard

Copied

Try this:

if (event.target.value != "Off") { 

 

// save the Old date 

this.getField("PrevDate").value = this.getField("todaysDate").value;

// get todays date object 

var oNow = new Date(); 

var sNow = util.printd("yyyy/mm/dd", oNow); 

// set date now 

this.getField("todaysDate").value = sNow; 

 

} else { 

// box is unchecked 

//Set the Old date 

var OrgDate = this.getField("PrevDate").value; 

this.getField("todaysDate").value = OrgDate; 

 

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
Engaged ,
Apr 30, 2018 Apr 30, 2018

Copy link to clipboard

Copied

LATEST

Thank you for your help

Best
M.Hasanain

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