Jump to content

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.