Copy link to clipboard
Copied
I need help with writing a javascript to create a Custom Date Format or a Custom Category that sets a 1 year range:
So, the format that should look something like yyyy - yyyy+1. The top range is 2 years back from the year the application was filled out and the bottom range is 1 year back.
Attached is the form that I would like to modify. The entry in question is on page 10 of the Application Form.
Copy link to clipboard
Copied
You can't use the Date format for this. You'll need to write your own Format (and Validate) scripts to achieve it.
However, if the values all depend on the year the form was filled in then you might as well use a calculation script and do it automatically for the user.
Copy link to clipboard
Copied
Hello and thanks for the prompt answer. It would be great if the entries for the years were automatic depending on the current year. I am not that versed in javascript, I would appreciate it if you could help me with the calculation script. Or tell me where I can get the help if you don't write script for people. I have attached my "working on" copy of the application if it might help. Again it is on page 10, #3 and the current year is at the top of every page. Thanks!
Billy (510) 329-4891
Copy link to clipboard
Copied
First of all, you have an error in the "Today" doc-level script which you should fix.
So assuming it's the "Year 1" and "Year 2" fields you can use this code as a doc-level script:
this.getField("Year 1").value = new Date().getFullYear()-1;
this.getField("Year 2").value = new Date().getFullYear()-2;
You'll need to change their Format to None, though.
Copy link to clipboard
Copied
Sorry, but where is the "Today" error? Also, the script for "Year 2" gives 2019 and the script for "Year 1" gives 2020. Like the Current Year at the top of the page 2020-2021, "Year 2" and "Year 1" should be calculated as 2018-2019 and 2019-2020, respectively. Sorry to bother you again.
Copy link to clipboard
Copied
Open the JS Console and you'll see the error message.
The code I provided uses the current year, as I did not see which field you're referring to. Please provide the exact field name.