function initAjaxRequest() { var request; if (window.ActiveXObject) { request = new ActiveXObject("Microsoft.XMLHTTP"); } else { request = new XMLHttpRequest(); } return request; } function sendAjaxGetRequest(url, container) { ajaxRequest = initAjaxRequest(); var rand = Math.random(); ajaxRequest.open('GET', ''+url+'&rand='+rand+''); ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); ajaxRequest.onreadystatechange = function() { if (ajaxRequest.readyState == 4) { var gegevens = ajaxRequest.responseText; var woord = gegevens.split(":"); document.getElementById('adres1').value = woord[0]; document.getElementById('plaats').value = woord[1]; } } ajaxRequest.send(null); } function ShowSearchPreview(fieldname){ var string = document.getElementById(fieldname).value; string = string.replace(" ", ""); document.getElementById(fieldname).value = string; if(string.length == 6) { sendAjaxGetRequest('templates/content/postcode.php?postcode='+string+''); } }