Wrox Programmer Forums
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 4th, 2006, 10:28 AM
Friend of Wrox
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default Why isn't this working?

Here is my code with some comments:

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


    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"


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

\'sync\' &lt;cr&gt;
The name specified is not recognized as an internal or external command, operable program or batch file.
Old January 5th, 2006, 11:01 AM
Friend of Wrox
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post

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



Old January 6th, 2006, 03:52 AM
Friend of Wrox
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts

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:


You were right on the positioning too. Thanks for the help!


Similar Threads
Thread Thread Starter Forum Replies Last Post
window.opener working .... not working alyeng2000 Javascript How-To 5 January 5th, 2007 08:05 AM
Web.Config..Working or Not Working peace95 ASP.NET 1.0 and 1.1 Basics 1 September 18th, 2006 06:53 AM
Local COM working , but not working at Web Serv nagen111 .NET Web Services 3 February 19th, 2005 04:22 AM
Example not working CKucler BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 3 December 8th, 2004 11:26 AM
Get Working Copy... not working Enkiel Classic ASP Basics 0 April 21st, 2004 01:41 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.