Dynamic date as initial value on entry field
May 22, 2017 12:00 AM
For my next trick...
I'm trying to figure out how to dynamically set two entry fields based on the current date. In this case, when the screen opens by default, the first entry should be 30 days prior to the current date and the second the actual current date.
The CurrentDate variable built in includes the day, but I only want the mm/dd/yyyy format. I was poking around and found a site that shows how to get the display right.
http://jsfiddle.net/9xWUT/
Edit: The code worked when I did a RunJS on the entry field, however there were a couple issues. The font style I defined did not hold and apply to the entry field. Nor could I edit the entry field to change the date. Worst case scenario is that I use text boxes with ChangeContent, but it would be pretty nifty if I could have a default and allow editing of the field.
Discussion (2)
It should work if you don't target the input field but the input fields variable. Run javascript on page level (On: Show) with two input fields. You may have to adjust the variable names in the script:
var newDate1 = new Date();
var newDate2 = new Date();
newDate1.setDate(newDate1.getDate() - 30);
newDate2.setDate(newDate2.getDate());
VarEntry_0001.set((newDate1.getMonth() + 1) + ';/'; + newDate1.getDate() + ';/'; + newDate1.getFullYear());
VarEntry_0002.set((newDate2.getMonth() + 1) + ';/'; + newDate2.getDate() + ';/'; + newDate2.getFullYear());
I didn't think of running it at the page show - that works beautifully! Down the road as I make improvements over time, I'll likely set this up so that it changes based on the selection of a drop down. Some of the choices will be tricky, since they're sort of based on the current date (ie. last period, this period, etc.).
Thanks, Tim!
Discussions have been disabled for this post