I’m unclear how to get this function to display “document.getElementById(“txtHint”).innerHTML=xmlhttp.responseText;” inside the div. Will you show me please?
Script:
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('mydiv2').innerHTML=txt;
}
}
OK. I’ve worked on this some more and got it to work the way I need to work. How could I clean it up and what issues do you see? Please be a kind as possible this is my first javascript function.
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;
}
If xmlhttp.responseText is not appearing inside the div whose id is txtHint, then there is a problem somewhere else in your code.
If you haven’t already done so, change the name of the variable currently called div. It might not be an issue in this case, but you shouldn’t have variable names the same as html element names.