PDA

View Full Version : printing a variables in javascript



joon
01-14-2009, 12:03 AM
1) Script Title: Cool DHTML Tooltip

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex5/dhtmltooltip.htm

3) Describe problem:


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.


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.")

[b] target result

"The value of offsetHeight is 100."

jscheuer1
01-14-2009, 06:44 AM
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:


<div id="mytestdiv"></div>

Then in your script 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;
}

Twey
01-14-2009, 07:00 AM
Perhaps alert (https://developer.mozilla.org/En/DOM:window.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).