|
Subject:
|
Why isn't this working?
|
|
Posted By:
|
interrupt
|
Post Date:
|
1/4/2006 9:28:31 AM
|
Here is my code with some comments:
<SCRIPT LANGUAGE="JavaScript"> var mkdiv = document.createElement('div'); //create your div var timer //create timer variable function showItem(posleft, postop, w, h, linkdetail, n)
//posleft = position from the left //postop = position from the top //w = pixelwidth //h = pixelheight //linkdetail = URL to be shown in the revealed div //n = text for URL to be shown in the revealed div //linkno = string built from linkdetail + n to give innerHTML string for divs innerHTML property.
{
linkno ="<a href = " + "\"" + linkdetail + "\"" + ">" + n + "</a>"
window.clearTimeout(timer) mkdiv.style.backgroundColor = "lightblue"; mkdiv.style.border = "1px solid black"; mkdiv.style.visibility = "visible" mkdiv.style.pixelLeft = posleft mkdiv.style.pixelTop = postop mkdiv.style.pixelWidth = w mkdiv.style.pixelHeight = h mkdiv.style.zIndex = 1 mkdiv.innerHTML = linkno //all of this syntax looks fine to me, Im just setting variables using arguments! timer = window.setTimeout("hidewin()", 5000) }
function hidewin(){ mkdiv.style.visibility = "hidden" }
</SCRIPT>
<a href = "#" onmouseover="showItem(100, 20, 100, 20, this.linkdetail, this.linktext)" linkdetail = "www.google.com" linktext = "Google">Show Link 1</a><br> <a href = "#" onmouseover="showItem(100, 40, 100, 20, this.linkdetail, this.linktext)" linkdetail = "www.yahoo.com" linktext = "Yahoo">Show Link 2</a>
The script is running without any complaints, but I can't see the div at all! Any ideas? All arguments are passed in on the onmouseover event, such as width and height, position, stuff like that, but I just cannot see the divs as they are 'supposed' to appear.
Help much appreciated.
Joe
|
|
Reply By:
|
ChrisScott
|
Reply Date:
|
1/5/2006 10:01:51 AM
|
Hi Joe,
It looks like you are creating the div, but never actually appending it to any element in the page.
Try adding this to your script block...
window.onload = function(){
document.body.appendChild( mkdiv );
};
I think you may also want to set style.position = "absolute" for the div
HTH,
Chris
|
|
Reply By:
|
interrupt
|
Reply Date:
|
1/6/2006 2:52:24 AM
|
Hi Chris,
Thanks for the tip. You were right, I wasn't appending to an element, but instead of using your piece of script I used:
document.body.insertBefore(mkdiv)
You were right on the positioning too. Thanks for the help!
Joe
|
|