RLJ Posted April 18, 2011 Share Posted April 18, 2011 Hi all, I have the following JavaScript function that I want to use to position div's on the page: <script type="text/javascript" language="JavaScript"> function SetPosition() { var HEADHeight = document.getElementById('HEAD').offsetHeight; if (document.getElementById('BANNER') { document.getElementById('BANNER').style.top = HEADHeight + 10 +'px'; var BANNERHeight = document.getElementById('BANNER').offsetHeight + 5; } else { var BANNERHeight = 0; } document.getElementById('CORE').style.top = HEADHeight + BANNERHEIGHT + 10 +'px'; var COREHeight = document.getElementById('CORE').offsetHeight + 5; if (document.getElementById('ADS') { document.getElementById('ADS').style.top = HEADHeight + BANNERHEIGHT + COREHeight + 10 +'px'; var ADSHeight = document.getElementById('ADS').offsetHeight + 5; } else { var ADSHeight = 0; } document.getElementById('TAIL').style.top = HEADHeight + BANNERHEIGHT + COREHeight + ADSHeight + 60 +'px'; } </script> I call this function on the body load as follows: <body onload="SetPosition()"> The above function is not working, it's not changing the position of the divs. Can someone see why? I'm not very knowledgeable on JavaScript, but it seems like it should work. The function was working before, until I changed the following: - body onload="SetPosition()" instead of: body onload="SetPosition('CORE', 'ADS', etc.)" - added the if statements to check whether the div exists. Thanks a lot! Link to comment https://forums.phpfreaks.com/topic/234088-page-layout-script-not-working/ Share on other sites More sharing options...
RLJ Posted April 18, 2011 Author Share Posted April 18, 2011 Sorry, just noticed there are brackets missing from the if statements, adding extra brackets didnt help though. Just to clarify, script is actually as follows: <script type="text/javascript" language="JavaScript"> function SetPosition() { var HEADHeight = document.getElementById('HEAD').offsetHeight; if (document.getElementById('BANNER')) { document.getElementById('BANNER').style.top = HEADHeight + 10 +'px'; var BANNERHeight = document.getElementById('BANNER').offsetHeight + 5; } else { var BANNERHeight = 0; } document.getElementById('CORE').style.top = HEADHeight + BANNERHEIGHT + 10 +'px'; var COREHeight = document.getElementById('CORE').offsetHeight + 5; if (document.getElementById('ADS')) { document.getElementById('ADS').style.top = HEADHeight + BANNERHEIGHT + COREHeight + 10 +'px'; var ADSHeight = document.getElementById('ADS').offsetHeight + 5; } else { var ADSHeight = 0; } document.getElementById('TAIL').style.top = HEADHeight + BANNERHEIGHT + COREHeight + ADSHeight + 60 +'px'; } </script> Link to comment https://forums.phpfreaks.com/topic/234088-page-layout-script-not-working/#findComment-1203189 Share on other sites More sharing options...
RLJ Posted April 18, 2011 Author Share Posted April 18, 2011 never mind, just spotted at typo...... Link to comment https://forums.phpfreaks.com/topic/234088-page-layout-script-not-working/#findComment-1203236 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.