Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Default year in Date field

Avatar

Level 3

Hi I am creating a Date of Birth field in a form and was wondering if there was a way to alter the deafult year. Most users will be at least 25 so it would make sense to have my date drop down show you 1987 (for example) when it drops downs so that users don't have a far back to navigate.  Is this possible?

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 6

here is a generic script that might help you.... I used this JavaScript in 'docReady' event of the Year dropdown...

if (this.rawValue == null || this.rawValue == "") {

    var d = new Date();

    var setValue = d.getFullYear() -25;

    this.rawValue = setValue;

}

View solution in original post

2 Replies

Avatar

Correct answer by
Level 6

here is a generic script that might help you.... I used this JavaScript in 'docReady' event of the Year dropdown...

if (this.rawValue == null || this.rawValue == "") {

    var d = new Date();

    var setValue = d.getFullYear() -25;

    this.rawValue = setValue;

}

Avatar

Level 3

Thank you, that does just what I want. 

The only little change I would like to make (if possible) is that I would like the DATE field to display empty when the form is first opened.  Is that possible? or do you need the date displayed to make the drop down to understand to show a date 25 years ago?