...

View Full Version : displaying php output into div



niche
09-07-2011, 02:51 AM
I thought I knew how, but I'm unclear how to get this function to display: "document.getElementById("txtHint").innerHTML=xmlhttp.responseText;" inside the div. Will you show me please?


xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
var div = document.createElement('div');
div.setAttribute('id', 'txtHint');
div.setAttribute("style","background-color:red;");
div.style.width = '300px';
div.style.height = '100px';
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
//var txt='hello world!';
document.getElementsByTagName('body')[0].appendChild(div);
document.getElementById('textHint').innerHTML=txt;
}
}

niche
09-07-2011, 03:49 AM
I worked it out. Here's my solution:
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
var div = document.createElement('div');
div.setAttribute('id', 'link_container');
div.setAttribute("style","background-color:white;");
div.style.width = '300px';
div.style.height = '100px';
div.style.margin = '-15px 0px 0px 75px';
var txt=document.innerHTML=xmlhttp.responseText;
document.getElementsByTagName('body')[0].appendChild(div);
document.getElementById('link_container').innerHTML=txt;
}

Old Pedant
09-07-2011, 03:49 AM
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
var div = document.createElement('div');
div.setAttribute('id', 'txtHint');
div.setAttribute("style","background-color:red;");
div.style.width = '300px';
div.style.height = '100px';
div.innerHTML=xmlhttp.responseText;
document.getElementsByTagName('body')[0].appendChild(div);
}
}


Though instead of doing

div.setAttribute("style","background-color:red;");
div.style.width = '300px';
div.style.height = '100px';

why not do

div.className = "MyBigFatRedDiv";

and set up the style in your CSS?

niche
09-07-2011, 04:34 AM
Thank-you very much. You answered a couple questions that I've been meaning to ask. How very Zen of you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum