Below is the code to populate hidden fields in my form based on the number of items present in an multi choice field. I find it difficult to create gift_1, gift_2, which is where I need your help. Thanks
if (selectedValues.length > 0) {
for (var i = 0; i < selectedValues.length; i++) {
jQuery("input[name=gift_1]").val(selectedValues[i]);
}
}
jQuery(`input[name='gift_${i}']`)? Starting from 0 or from 1?selectedValues.forEach((val, index) => document.querySelector(`input[name='gift_${index + 1}']`).value = val);