javascript add option element to select
javascript add option/element to select:
const newOpt = document.getElementById('option-input');
let mySelect = document.getElementById('mySelect'); //Object not array
const opts = Object.values(mySelect.options);
const option = document.createElement('option');
optValues = opts.map(opt => opt.value.toLowerCase());
//Validate if option exists
if(optValues.indexOf(newOpt.value.toLowerCase()) !== -1){
newOpt.nextElementSibling.after("Category exists");
}else{
option.value = newOpt.value;
option.text = newOpt.value;
mySelect.add(option);
mySelect.value = option.value;
}
Also in JavaScript:
- node load file
- how to get the value of radio button in jquery
- sonarqube for angular application
- bigint type js
- js copy array into another
- how to get value of button that click on it jquery
- js array.pop
- javascript use variable regex
- export multiple functions react
- add condition inside a className in reactjs
- install node js in manjaro
- jquery ajax upload image
- UltraExploit.js
- rorate array
- index of value in array
- input output ionic
- c# beautify json string
- push a new route only triggers URL change but not location change
- javascript sort array of object by property
- vuejs enter phone with country flag
- javascript reduce
- string charAt array js
- how to get the square root in js
- javascript minute and second to convert seconds