You are viewing limited content. For full access, please sign in.

Question

Question

Field values created by Javascript not appearing in Forms submission view or in repository upload

asked on July 23, 2021

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!

1 0

Answer

SELECTED ANSWER
replied on July 26, 2021

Figured it out.

After inspecting the drop-down element in the browser, noticed that the value attribute had "0-4" respectively for the 5 academic years.

Since this is happening before the submission, I realized that the JS was assigning the value of the iterator as the value.

+ ' value=' + i + '>'

so I fixed this by changing what gets assigned to the value

+ ' value=' + ((yrInt) + i) + ((yrInt + 1) + i) + '>'

 

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.