Before I go on, lemme just say that I don't know squat about javascript. That being said... I am using the following javascript to load results onto my page... var xml = xmlObject(); var url; var button; var result; function xmlObject () { if (typeof XMLHttpRequest == 'undefined') { objects = Array( 'Microsoft.XmlHttp', 'MSXML2.XmlHttp', 'MSXML2.XmlHttp.3.0', 'MSXML2.XmlHttp.4.0', 'MSXML2.XmlHttp.5.0' ); for (i = 0; i < objects.length; i++) { try { return new ActiveXObject(objects[i]); } catch (e) {} } } else { return new XMLHttpRequest(); } } function resultElement () { if (!document.getElementById('result')) { result = document.createElement('div'); result.id = 'result'; document.body.appendChild(result); } } function handleResults () { if (xml.readyState == 4) { if (xml.responseText == 'url.blank') { result.innerHTML = 'Enter a valid URL'; } else { result.innerHTML = xml.responseText; } } else { result.innerHTML = 'Loading..'; } } function getResults () { resultElement(); xml.open('get', 'results.php?url=' + escape(url.value)); xml.onreadystatechange = handleResults; xml.send(null); } function loadHandler () { url = document.getElementById('url'); button = document.getElementById('button'); button.onclick = getResults; } window.onload = loadHandler; HTML: problem is, the results are loading at the bottom of my page. Is there a way to make it load in a specified div?
ive narrowed it down to this portion... function resultElement () { if (!document.getElementById('result')) { result = document.createElement('div'); result.id = 'result'; document.body.appendChild(result); } } HTML: ... instead of creating a div I would like it to load on an existing div Test page is here
change the function resultElement to following function resultElement () { return; } } Code (markup): Now just make the id of that div "result" where you wants results to be displayed. <div id="result">This is my existing div</div> Code (markup): Not tested, but it should work. Thanks.