I have a JavaScript automated form creation formula. I'm struggling with the "selected" attribute of an option in a select list.
I'd like to have the option selected which matches the const c (in this case, I'd like to have the option "Formation" selected).
How can I achieve this?
const c = "Formation";
const training_level = document.createElement('select');
training_level.setAttribute('value', c)
training_level.setAttribute('id', 'rec_mode')
training_level.required = true
var j = new Array("-- Type de diplôme --","Formation","Brevet","Bac","Bac +1"),
var options = '';
for (var i = 0; i < j.length; i++) {
options += '<option value="' + j[i]+ '">' + j[i] + '</option>';
}
training_level.appendChild(options);