AaronCampbell
04-06-2004, 02:52 PM
Well, I'm going to be making a pop-up (well, not pop-up, it'll be in a hidden div that disappears and re-appears), but I'm having problems positioning it. I want to position the calendar in relation to the image that is clicked to call it up. I gave the image an ID, and I pass that as an argument in the function. The code below works fine in IE, but not in mozilla. In mozilla the div appears at top:200 left:200 no matter what. What do I need to do to make it cross-browser?
document.write("<div style=\"position:absolute; visibility:hidden; top:200px; left:200px;\"
id=\"calendar_container\">THIS IS A TEST!!!</div>");
function show_calendar(target,parent,adjLeft,adjRight)
{
var calendar_container = document.getElementById('calendar_container');
var parentID = document.getElementById(parent);
var offsetLeft = getWindowOffsetLeft(parentID);
var offsetTop = getWindowOffsetTop(parentID);
calendar_container.style.left = offsetLeft+adjLeft;
calendar_container.style.top = offsetTop+adjRight;
calendar_container.style.visibility = 'visible';
var date='2004-01-04';
write_date(target,date);
}
function write_date(target,date)
{
target = eval('document.'+target);
target.value=date;
}
function getWindowOffsetLeft(item)
{
var offset = item.offsetLeft;
var parent = item.offsetParent;
while(parent.tagName.toLowerCase()!="body")
{
offset += parent.offsetLeft;
parent = parent.offsetParent;
}
return offset;
}
function getWindowOffsetTop(item)
{
var offset = item.offsetTop;
var parent = item.offsetParent;
while(parent.tagName.toLowerCase()!="body")
{
offset += parent.offsetTop;
parent = parent.offsetParent;
}
return offset;
}
document.write("<div style=\"position:absolute; visibility:hidden; top:200px; left:200px;\"
id=\"calendar_container\">THIS IS A TEST!!!</div>");
function show_calendar(target,parent,adjLeft,adjRight)
{
var calendar_container = document.getElementById('calendar_container');
var parentID = document.getElementById(parent);
var offsetLeft = getWindowOffsetLeft(parentID);
var offsetTop = getWindowOffsetTop(parentID);
calendar_container.style.left = offsetLeft+adjLeft;
calendar_container.style.top = offsetTop+adjRight;
calendar_container.style.visibility = 'visible';
var date='2004-01-04';
write_date(target,date);
}
function write_date(target,date)
{
target = eval('document.'+target);
target.value=date;
}
function getWindowOffsetLeft(item)
{
var offset = item.offsetLeft;
var parent = item.offsetParent;
while(parent.tagName.toLowerCase()!="body")
{
offset += parent.offsetLeft;
parent = parent.offsetParent;
}
return offset;
}
function getWindowOffsetTop(item)
{
var offset = item.offsetTop;
var parent = item.offsetParent;
while(parent.tagName.toLowerCase()!="body")
{
offset += parent.offsetTop;
parent = parent.offsetParent;
}
return offset;
}