I want to display option dynamically after from input text before comma but it is not displaying the option in select tag. For eg if the user types hello and then types comma (,) the value before comma should display on option inside select tag with multiple attributes.
Here is my code:
var skills = document.querySelector('#skills');
var skillhave = document.querySelector('#skill');
var skillshaving = [];
skills.addEventListener('keyup', function(event) {
if (event.keyCode === 188) {
if (this.value.length < 2) {
alert("skill required");
this.value = "";
} else {
var skill = this.value.substring(0, this.value.length - 1);
skillshaving.push(skill);
this.value = "";
reloadskills();
}
}
});
function reloadskills() {
skillhave.innerHTML = "";
for (var i = 0; i < skillshaving.length; i++) {
var opt = document.createElement('option');
opt.value += $ {
skillshaving[i]
};
opt.innerHTML += $ {
skillshaving[i]
};
skillhave.appendChild(opt);
}
}
<input type="text" class="form-control" placeholder="Enter skill" name="skills" id="skills"> <!-- for entering skills via text -->
<select name="" id="skill" multiple></select> <!-- for displaying it in option tag -->