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
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;
}
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
}
Copy link to clipboard
Copied
Where did you set the value of the field "PrevDate"?
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
Copy link to clipboard
Copied
In the properties of the field you can set it as hidden.
Copy link to clipboard
Copied
yes i do that, but i wondering, are this the best solution ?
Copy link to clipboard
Copied
No. What kind of old date want you?
Copy link to clipboard
Copied
old date simply is the re written date in the field before hitting the checkbox
Copy link to clipboard
Copied
Save the value before you change value of this field.
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 ?
Copy link to clipboard
Copied
What code do you use?
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.
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;
}
Copy link to clipboard
Copied
Thank you for your help