Forum Moderators: open

Message Too Old, No Replies

Help Diagnosing Error

Invalid Argument

         

nwhorton

5:03 pm on Sep 28, 2005 (gmt 0)

10+ Year Member



On one of my websites I use an ASP script to resize the navigation bar on the left so that it always extends to the bottom of the page, even when there is a lot of content in the body. The script works fine, however as you'll noticed I'm getting an error on each page that appears to be coming from this code. Here is the script:

<script type=text/javascript>

function adjustHeight()
{
var col_1 = document.getElementById("content-col-1");
var col_2 = document.getElementById("content-col-2");
var nav3 = document.getElementById("navbar3");
var adj1 = document.getElementById("adj1");
var adj2 = document.getElementById("adj2");
var adj_height = Math.max(col_1.offsetHeight, col_2.offsetHeight) - nav3.offsetHeight - (adj2.offsetHeight / 2) - 10;
document.getElementById('navbar3').style.paddingBottom = adj_height + "px";
}
</script>

According to IE, the error is in the final line, character 2 reported as "invalid argument"...does anyone recognize the problem? The page can be viewed at www.careercenter.uiuc.edu

Bernard Marx

5:21 pm on Sep 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I thought that the browser didn't like the possible non-integer paddingBottom value (possible, since there's a division in the calculation).
- It's not that though. Browsers don't appear to mind.

We'll probably need to know more. Meanwhile, you could try outputting the value that you're getting..

alert(adj_height + "px")

Slip that in after the calculation (but before the attempted assignment to the element).

Bernard Marx

5:23 pm on Sep 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PS. I get the error: "invalid argument" when I try to assign a negative paddingBottom value. Perhaps that's a pointer for you.

nwhorton

6:24 pm on Sep 28, 2005 (gmt 0)

10+ Year Member



Yes, looks like you've found it. The alert shows that the value is indeed negative. Any suggestions?

Bernard Marx

7:37 pm on Sep 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



er...make sure it's not negative (?!)

I don't know how you'd do that, apart from simply zeroing all negative values:

if(adj_height<0) adj_height = 0;

Overall, it may be a good idea to pop over to the CSS forum [webmasterworld.com], and ask them if they have a good template for a 2 column page. You might be able to avoid any scripting.

nwhorton

7:25 pm on Sep 29, 2005 (gmt 0)

10+ Year Member



I changed the code so it reads


{
var col = document.getElementById("content-col-1A");
var nav3 = document.getElementById("navbar3");
var adj1 = document.getElementById("adj1");
var adj2 = document.getElementById("adj2");
var adj_height = col.offsetHeight - nav3.offsetHeight - (adj2.offsetHeight / 2) - 10;
var abs_height = Math.abs(adj_height);
document.getElementById('navbar3').style.paddingBottom = abs_height + "px";
}

This gets rid of the negative value and the function sitll works properly, however, now I'm getting an error in line 39 char 2 "Object Required".

The line is


var adj_height = col.offsetHeight - nav3.offsetHeight - (adj2.offsetHeight / 2) - 10;

What is wrong with the syntax there?

Bernard Marx

8:58 pm on Sep 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nothing wrong that I can see. Try dragging an alert through the function - line by line - and seeing what you get for each variable.