Explore the community Forums Lectora Lectora Questions & Answers Dynamic date as initial value on entry field

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #357207 Score: 0
    Profile photo of Jason Dalrymple
    Jason Dalrymple
    Member
    beginner
    intermediate
    profile
    wise owl
    curious george
    contributor
    friend finder
    advanced
    picture perfect
    48 pts
    @JasonADal

    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.

    • This topic was modified 2 years, 10 months ago by Profile photo of Jason Dalrymple Jason Dalrymple. Reason: experimented and was able to get code to work
    #357305 Score: 2
    Profile photo of Tim K
    Tim K
    Member
    contributor
    beginner
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    wise owl
    curious george
    Group Member
    334 pts
    @timk

    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());
    This post has received 2 votes up.
    #357399 Score: 0
    Profile photo of Jason Dalrymple
    Jason Dalrymple
    Member
    beginner
    intermediate
    profile
    wise owl
    curious george
    contributor
    friend finder
    advanced
    picture perfect
    48 pts
    @JasonADal

    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!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.