/    Sign up×
Community /Pin to ProfileBookmark

Positioning a DIV in JavaScript – IE 6 problems

Hi Guys,

I’ve created a page with an image of a man where a user is able to click on an area and a div is positioned at that point containing a white circle. This code works in all browsers except IE 6 where it creates a duplicate white circle beneath the one which is placed in the correct location. Could anyone tell me how to get rid of this second circle? The circle is essentially a div with a background image assigned. Please see my code below:

[code]
<&#37;@ Page Language=”VB” AutoEventWireup=”false” CodeFile=”ImageClick.aspx.vb” Inherits=”ImageClick” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
<title>Image Click</title>

<script type=”text/javascript” language=”javascript” src=”JQuery.js”></script>

<script language=”javascript” type=”text/javascript”>
window.onload = Init

function Init()
{
document.getElementById(“divBlackSpot”).style.display = “none”;
}

function getCoordinates(e)
{
var el = e.target || e.srcElement;

// Get mouse click co-ords
var ePos = {x:0, y:0};
if (‘number’ == typeof e.pageX)
{
ePos.x = e.pageX;
ePos.y = e.pageY;
}
else if (‘number’ == typeof e.clientX)
{
ePos.x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
ePos.y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
}

// Get image top left co-ords
var elPos = {x:0, y:0};
if (el.offsetParent)
{
elPos.x = el.offsetLeft;
elPos.y = el.offsetTop;

while (el = el.offsetParent)
{
elPos.x += el.offsetLeft;
elPos.y += el.offsetTop;
}
}

// Write relative position of click to form controls
// var clickedXPosition = (ePos.x – elPos.x);
// var clickedYPosition = (ePos.y – elPos.y);

var clickedXPosition = ePos.x – 5;
var clickedYPosition = ePos.y – 5;

// Position a black dot over the clicked area
document.getElementById(“divBlackSpot”).style.display = “inline”;
document.getElementById(“divBlackSpot”).style.position = “absolute”;
document.getElementById(“divBlackSpot”).style.top = clickedYPosition + “px”;
document.getElementById(“divBlackSpot”).style.left = clickedXPosition + “px”;

//alert(“Clicked X Position = ” + clickedXPosition + “rnClicked Y Position = ” + clickedYPosition);

}
</script>
</head>
<body>
<form id=”form1″ runat=”server” action=”ImageClick.aspx” method=”post”>
<div style=”cursor: pointer;”>
<img src=”images/man.png” alt=”Man” usemap=”#map1″ />
<map id=”map1″ name=”map1″>
<area shape=”poly” alt=”” title=”” coords=”170,70,157,77,157,88,149,88,162,109,143,120,130,118,123,125,57,133,19,134,35,148,50,144,58,144,66,140,99,146,140,141,147,175,143,207,143,216,140,263,136,306,143,364,130,375,146,381,153,367,153,355,149,346,157,312,155,295,168,230,166,220,175,222,174,246,185,303,184,320,189,332,188,372,198,382,211,378,200,362,200,352,206,310,202,287,202,244,197,206,198,199,193,179,198,140,235,144,247,147,282,143,293,145,311,149,316,139,302,132,269,134,240,128,235,131,221,126,201,117,195,121,178,107,180,99,186,98,186,86,182,87,181,77,170,70″ style=”cursor: pointer;” onclick=”getCoordinates(event)” />
</map>
</div>
<div id=”divBlackSpot” style=”height: 10px; width: 10px; background-image: url(images/blackdot.gif); cursor: pointer;”></div>
</form>
</body>
</html>
[/code]

Thanks,

Tim

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@PadonakJul 20.2010 — Tim have you ever heard about bbcode?
Copy linkTweet thisAlerts:
@TimH83authorJul 20.2010 — Hi Padonak,

I haven't heard of bbcode. Could you tell me what it is and how it could be used to solve my problem please?

Thanks,

Tim
Copy linkTweet thisAlerts:
@TimH83authorJul 20.2010 — One thing I've just noticed. The code refers to "BlackDot" in a few places. The dot is white, it's just that I'm developing locally at the moment so I couldn't be bothered to rename files.
Copy linkTweet thisAlerts:
@PadonakJul 20.2010 — i mean these forum tags above the posting textarea. these are for posting your HTML, scripts etc.
Copy linkTweet thisAlerts:
@TimH83authorJul 20.2010 — Why are these necessary? I've pasted the code into the window so I can't see the problem.
×

Success!

Help @TimH83 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...