The following code displays results data from the table according to the choice from HTML select box, but it appends the new results to the previous one. How to display only the current selected data?
<script>
function GetSelectedText() {
const trips = [
["AAA", "London"],
["AAA", "Manchester"],
["AAA", "Oxford"],
["BBB", "Paris"],
["BBB", "Lyon"],
["BBB", "Marsylia"],
["CCC", "Berlin"],
["CCC", "Hamburg"],
["CCC", "Bonn"]
]
var oSel = document.getElementById("country");
var wybrano = oSel.options[oSel.selectedIndex].text;
var parent = document.getElementById("wybrano");
for (var i = 0; i < 9; i++) {
if (wybrano == trips[i][0]) {
divy = document.createElement("div");
divy.innerHTML = '<p>' + i + ' ' + trips[i][1] + '</p>';
document.body.appendChild(divy);
}
}
}
</script>
<form id="Forma">
<select id="country" onChange="GetSelectedText()">
<option value="0"> country </option>
<option value="1"> AAA </option>
<option value="2"> BBB </option>
<option value="3"> CCC </option>
</select>
</form>
<div id="content"></div>