I have several text fields. I would like to place the values from the input fields into a drop down menu. If the text is changed I would like for the drop down menu to be updated. Here's the closest I have gotten.
function insertLab1() {
var x = document.getElementById("insLabels");
var option1 = document.createElement("option");
var label1 = document.getElementById("lab1").value;
option1.text = label1;
x.add(option1, x[0]);
if (label1 != option1.text){x.remove(x.options[0]);}
}
function insertLab2() {
var x = document.getElementById("insLabels");
var option2 = document.createElement("option");
var label2 = document.getElementById("lab2").value;
option2.text = label2;
x.add(option2, x[1]);
if (label2 != option2.text){x.remove(option2);}
}
Label 1 <input type="text" id="lab1" onchange="insertLab1()"><br>
Label 2 <input type="text" id="lab2" onchange="insertLab2()"><br><br>
Choose Label<br>
<select id="insLabels">
</select>
The labels do show up in the option drop down list but the drop down values will not change when the text is changed in the label areas. I have tried multiple combinations within the if statements but nothing seems to be working for me.
Any thoughts on what I have been doing wrong? Thank you so much for any help you can offer!