Results 1 to 3 of 3

Thread: printing a variables in javascript

  1. #1
    Join Date
    Apr 2005
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default printing a variables in javascript

    1) Script Title: Cool DHTML Tooltip

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...tmltooltip.htm

    3) Describe problem:

    Code:
    if (bottomedge<tipobj.offsetHeight)
    tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
    else
    tipobj.style.top=curY+offsetypoint+"px"
    tipobj.style.visibility="visible"
    }
    }
    I like to print the value of offsetHeight.

    The following would-be code doesn't work correctly but it will show what I want.

    Code:
    [b]would-be code
    
    if (bottomedge<tipobj.offsetHeight)
    tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
    else
    tipobj.style.top=curY+offsetypoint+"px"
    tipobj.style.visibility="visible"
    }
    }
    
    print here ("The value of offsetHeight is variables.offsetHeight.")
    
     target result
    
    "The value of offsetHeight is 100."

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The way to print to a page is the document.write() method.

    But you cannot document.write() to a page once it is loaded without overwriting the page. So a target element to which you can either add or modify one of its text nodes, or modify its innerHTML property would be a good idea.

    If this is just for troubleshooting purposes, innerHTML will do just fine - Put a division on your page in the body area:

    HTML Code:
    <div id="mytestdiv"></div>
    Then in your script code:

    Code:
    if (bottomedge<tipobj.offsetHeight)
    tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
    else
    tipobj.style.top=curY+offsetypoint+"px"
    tipobj.style.visibility="visible"
    }
    document.getElementById('mytestdiv').innerHTML = 'The value of the tipobj offsetHeight is: ' + tipobj.offsetHeight;
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Perhaps alert() is what you want?

    innerHTML or status are also handy, for debugging purposes (especially if there is a fast flow of data, since alert() will block).
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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