Please bear with me.... My PHP is great but when it comes to javascript I suck horibly. I am working with some sample code thats part of an ajax form. It uses the following to insert text back into the main page: function resultElement () { if (!document.getElementById('result')) { result = document.createElement('div'); result.id = 'result'; document.body.appendChild(result); } } Code (markup): How would I modify this to insert where I want to on the main page? Right now it inserts back to the main page at the bottom no matter what I do... Help is greatly needed. Thanks.
If you use: var nBody = document.body.getElementsByTagName('*'); Code (markup): it will return an array of all the tags in the body. You can then use .insertBefore, for example, above the 3rd tag: var nBody = document.body.getElementsByTagName('*'); var nDiv = document.createElement('div'); document.body.insertBefore(nDiv,nBody[2]) Code (markup): or to insert above the form tag var nFloor = document.body.getElementsByTagName('form')[0]; var nDiv = document.createElement('div'); document.body.insertBefore(nDiv,nFloor); Code (markup): I didn't test this, but that is the approach.
Well, I could not get it to work with the code you posted so I went over the the MSDN center and did some reading for some well needed basic javascript skills. I ended up just using one line: result = document.getElementById('oIn'); Code (markup): And then wrote another function to change the innerHTML: function handleResults () { if (xml.readyState == 4) { if (xml.responseText == 'ins.blank') { result.innerHTML = 'Please Enter A Value!'; } else { result.innerHTML = xml.responseText; } } else { result.innerHTML = 'Working Please Wait'; } } Code (markup): Good thing I can learn quick