Howdy
My case requires me to dynamically fill a drop down field with options. I work in education and the drop down values should refer to the current academic year as well as the 4 upcoming academic years.
For example, the 2021-2022 academic year would appear as "2122".
The drop-down field should have the values:
- 2122
- 2223
- 2324
- 2425
- 2526
I was able to achieve this using the Javascript code attached below.
//Populate Academic Year drop-down field let dt = new Date(); let yr = dt.getFullYear().toString().substring(2,4); let yrInt = parseInt(yr); for(let i = 0; i < 5; i++){ $('#myDropDownField select').append('<option' + (i == 0 ? ' selected' : '') + ' value=' + i + '>' + ((yrInt) + i) + ((yrInt + 1) + i) + '</option>'); }
The drop-down appears correctly and allows the user to select when filling the form.
However, once submitted, the monitor page shows the variable value for the drop-down to be "0". The repository entry also shows the value to be "0".
Why is this happening?
Some Additional info:
- The drop down field in the forms editor does not have any options entered. It is blank. Options are only added when the JS runs.
- If I enter some default choices in the forms editor, the variable data is still "0" after the submission.
- The drop down field is not set to read-only.
Thank you all!