sayedsohail Posted July 1, 2007 Share Posted July 1, 2007 Hi everyone, I am having problem dynamically setting up the position showstatusdiv on the fly. I wish to set the top and left when i called showstatusdiv function. Here is the code: function showstatusdiv(boxcontents) { hidestatusdiv(); z=document.body.appendChild(document.createElement("div")); z.id = "statusbox"; z.style.position = "absolute"; if (self.pageYOffset != null) { z.style.top = self.pageYOffset + "px"; } else if (document.documentElement.scrollTop != null) { z.style.top = document.documentElement.scrollTop + "px"; } z.style.width = "50%"; z.style.left = "0px"; z.style.background = "#ffffff"; z.style.border = ".3em solid #ff0000"; z.style.padding = ".3em 1.3em .3em .3em"; z.style.zIndex = "1000"; z.innerHTML = '<div style="position: absolute; border: 1px solid black; top: 0px; right: 0px;"><span style="padding: .3em; font-weight: bold;"><a style="text-decoration: none;" title="Close status box" href="#" onclick="javascript:hidestatusdiv();">X</a></span></div>'; z.innerHTML += boxcontents; } Link to comment https://forums.phpfreaks.com/topic/57961-solved-how-to-set-top-left-of-div-dynamically/ Share on other sites More sharing options...
emehrkay Posted July 1, 2007 Share Posted July 1, 2007 try moving document.body.appendChild(z); to the end. define z as var z = document.createElement('div'); Link to comment https://forums.phpfreaks.com/topic/57961-solved-how-to-set-top-left-of-div-dynamically/#findComment-287295 Share on other sites More sharing options...
sayedsohail Posted July 1, 2007 Author Share Posted July 1, 2007 Can you please correct the code where i made mistakes, your help is greatly appreciated. As i am not that good with javascript. What exactly i want is to provide left and top, right margins when i called the function showstatusdiv("Test","200px","100px", "200px") i.e., margin-left 200px i.e., margin-top 100px i.e., margin-right 200px Thanks Link to comment https://forums.phpfreaks.com/topic/57961-solved-how-to-set-top-left-of-div-dynamically/#findComment-287305 Share on other sites More sharing options...
emehrkay Posted July 1, 2007 Share Posted July 1, 2007 oh, you want to pass parameters to the function and have them define the top and the left attributes? if so, function showstatusdiv(content, top, left){ ... z.style.left = left; z.style.top = top; ...} is that what you're looking for? Link to comment https://forums.phpfreaks.com/topic/57961-solved-how-to-set-top-left-of-div-dynamically/#findComment-287347 Share on other sites More sharing options...
sayedsohail Posted July 1, 2007 Author Share Posted July 1, 2007 oh sorry its working now.. i figured it out. it was somethign to do with passing arguments. thanks, Link to comment https://forums.phpfreaks.com/topic/57961-solved-how-to-set-top-left-of-div-dynamically/#findComment-287367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.