input and select box combined
<input type="text" list="cars" />
<datalist id="cars">
<option>Volvo</option>
<option>Saab</option>
<option>Mercedes</option>
<option>Audi</option>
</datalist>
input and select box combined
<input type="text" list="cars" />
<datalist id="cars">
<option>Volvo</option>
<option>Saab</option>
<option>Mercedes</option>
<option>Audi</option>
</datalist>
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;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us