can someone tell me how to make JavaScript put the responseText also in an input field and not only in a span? I want when I enter a postal code, that automatically in the field next to it the city is added. This is my code:
function plzsuche(inhalt) {
if (inhalt == "") {
document.getElementById("city").innerHTML = "no Place";
return;
}
if (window.XMLHttpRequest) {
// AJAX nutzen mit IE7+, Chrome, Firefox, Safari, Opera
xmlhttp = new XMLHttpRequest();
} else {
// AJAX mit IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
if (xmlhttp.responseText != "") {
document.getElementById("city").innerHTML = xmlhttp.responseText;
}
}
}
xmlhttp.open("POST", "<?=DIR?>ausgang/plzsearch?q=" + inhalt, true);
xmlhttp.send();
}
<div class="col-md-5">
<input type="number" maxlength="5" name="ZIP" id="ZIP" class="form-control" placeholder="ZIP" onkeyup="plzsuche(this.value)">
</div>
<div class="col-md-7">
<input type="text" name="place" id="place" class="form-control" value="">
<span id="city"></span>
</div>
The code works on this way (the span is then below the 'place' input field). But as soon as I use the span as value for the input field nothing comes back.Maybe one of you knows a simple solution.