JSFiddle - React, Tailwind, and code Playground
by IllusionMH
HTML
<select id="sel1">
<option value="1">111</option>
<option value="2">222</option>
<option value="3">333</option>
<option value="4">444</option>
</select>
<input type="text" id="inp1" />
<input type="text" id="inp2" />
JavaScript
document.getElementById("sel1").onchange = function() {
document.getElementById("inp1").value = this.value;
document.getElementById("inp2").value = this.options[this.options.selectedIndex].text;
};
document.getElementById("inp1").onchange = function() {
var sel = document.getElementById("sel1"),
i, n;
for (i = 0, n = sel.options.length; i < n; i += 1) {
if (this.value === sel.options[i].value) {
sel.options.selectedIndex = i;
document.getElementById("inp2").value = sel.options[i].text;
break;
}
}
};