Jump to content

Page layout script not working


RLJ

Recommended Posts

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.