Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2009
    Posts
    21
    Thanks
    6
    Thanked 0 Times in 0 Posts

    displaying php output into div

    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?

    Code:
    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;
        }
      }

  • #2
    New Coder
    Join Date
    Aug 2009
    Posts
    21
    Thanks
    6
    Thanked 0 Times in 0 Posts
    I worked it out. Here's my solution:
    Code:
    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;
        }

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 Posts
    Code:
    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
    Code:
          div.setAttribute("style","background-color:red;");
          div.style.width = '300px';
          div.style.height = '100px';
    why not do
    Code:
          div.className = "MyBigFatRedDiv";
    and set up the style in your CSS?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    niche (09-07-2011)

  • #4
    New Coder
    Join Date
    Aug 2009
    Posts
    21
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Thank-you very much. You answered a couple questions that I've been meaning to ask. How very Zen of you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •