I have an array Orte that contains postcode and the name of the city.
Now I want to change the dropdown depending on the number entered in the input field.
The input field has an onchange function. The function is the one below.
The script works so far except the last line after the for loop. It never adds the last part and I don't know why. Can someone help me please.
Thanks in advance for the anwsers! Burzi
function updateOrt(eingabe){
document.getElementById("ort_platzhalter").innerHTML = '<select name="ort">'
for (var i = 1; i <= Orte.length; i++){
if(Orte[i].PLZ == eingabe){
document.getElementById("ort_platzhalter").innerHTML += '<option value="' + Orte[i].id + '">' + Orte[i].Ort + '</option>'
}
}
document.getElementById("ort_platzhalter").innerHTML += "</select>"
}
i=0; i<Orte.length.innerHTML += htmlPart;will most likely never have the expected result. Whenever you changeinnerHTMLit will immediately parsed into DOM, as of that an incomplete html code will be fixed.innerHTML += "</select>"will never have an effect, as.innerHTMLcannot be incomplete.