[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4922
  • Last Modified:

Invalid Argument: document.getElementById(layer).style.left = x + "px";

Hello.

The following is giving me an error:

            document.getElementById(layer).style.left = x + "px";

The error is: Invalid Argument

Thanks!

--------------------------
// PHP Layers Menu 3.1.2 (C) 2001-2003 Marco Pratesi (marco at telug dot it)

layerLeft = new Array();
layerTop = new Array();

function setVisibility(layer,on) {
      if (on) {
            if (DOM) {
                  document.getElementById(layer).style.visibility = "visible";
            } else if (NS4) {
                  document.layers[layer].visibility = "show";
            } else {
                  document.all[layer].style.visibility = "visible";
            }
      } else {
            if (DOM) {
                  document.getElementById(layer).style.visibility = "hidden";
            } else if (NS4) {
                  document.layers[layer].visibility = "hide";
            } else {
                  document.all[layer].style.visibility = "hidden";
            }
      }
}

function isVisible(layer) {
      if (DOM) {
            return (document.getElementById(layer).style.visibility == "visible");
      } else if (NS4) {
            return (document.layers[layer].visibility == "show");
      } else {
            return (document.all[layer].style.visibility == "visible");
      }
}

function setLeft(layer,x) {
layerLeft[layer] = x;
      if (DOM && !Opera5) {


////////////////////////// The error is in the one line below ////////////////////

            document.getElementById(layer).style.left = x + "px";
      } else if (Opera5) {
            document.getElementById(layer).style.left = x;
      } else if (NS4) {
            document.layers[layer].left = x;
      } else {
            document.all[layer].style.pixelLeft = x;
      }
}

function getOffsetLeft(layer) {
      var value = 0;
      if (DOM) {      // Mozilla, Konqueror >= 2.2, Opera >= 5, IE
            object = document.getElementById(layer);
            value = object.offsetLeft;
//alert (object.tagName + " --- " + object.offsetLeft);
            while (object.tagName != "BODY" && object.offsetParent) {
                  object = object.offsetParent;
//alert (object.tagName + " --- " + object.offsetLeft);
                  value += object.offsetLeft;
            }
      } else if (NS4) {
            value = document.layers[layer].pageX;
      } else {      // IE4 IS SIMPLY A BASTARD !!!
            if (document.all["IE4" + layer]) {
                  layer = "IE4" + layer;
            }
            object = document.all[layer];
            value = object.offsetLeft;
            while (object.tagName != "BODY") {
                  object = object.offsetParent;
                  value += object.offsetLeft;
            }
      }
      return (value);
}

function setTop(layer,y) {
layerTop[layer] = y;
      if (DOM && !Opera5) {
            document.getElementById(layer).style.top = y + "px";
      } else if (Opera5) {
            document.getElementById(layer).style.top = y;
      } else if (NS4) {
            document.layers[layer].top = y;
      } else {
            document.all[layer].style.pixelTop = y;
      }
}

function getOffsetTop(layer) {
// IE 5.5 and 6.0 behaviour with this function is really strange:
// in some cases, they return a really too large value...
// ... after all, IE is buggy, nothing new
      var value = 0;
      if (DOM) {
            object = document.getElementById(layer);
            value = object.offsetTop;
            while (object.tagName != "BODY" && object.offsetParent) {
                  object = object.offsetParent;
                  value += object.offsetTop;
            }
      } else if (NS4) {
            value = document.layers[layer].pageY;
      } else {      // IE4 IS SIMPLY A BASTARD !!!
            if (document.all["IE4" + layer]) {
                  layer = "IE4" + layer;
            }
            object = document.all[layer];
            value = object.offsetTop;
            while (object.tagName != "BODY") {
                  object = object.offsetParent;
                  value += object.offsetTop;
            }
      }
      return (value);
}

function setWidth(layer,w) {
      if (DOM) {
            document.getElementById(layer).style.width = w;
      } else if (NS4) {
//            document.layers[layer].width = w;
      } else {
            document.all[layer].style.pixelWidth = w;
      }
}

function getOffsetWidth(layer) {
      var value = 0;
      if (DOM && !Opera56) {
            value = document.getElementById(layer).offsetWidth;
      } else if (NS4) {
            value = document.layers[layer].document.width;
      } else if (Opera56) {
            value = document.getElementById(layer).style.pixelWidth;
      } else {      // IE4 IS SIMPLY A BASTARD !!!
            if (document.all["IE4" + layer]) {
                  layer = "IE4" + layer;
            }
            value = document.all[layer].offsetWidth;
      }
      return (value);
}

function setHeight(layer,h) {      // unused, not tested
      if (DOM) {
            document.getElementById(layer).style.height = h;
      } else if (NS4) {
//            document.layers[layer].height = h;
      } else {
            document.all[layer].style.pixelHeight = h;
      }
}

function getOffsetHeight(layer) {
      var value = 0;
      if (DOM && !Opera56) {
            value = document.getElementById(layer).offsetHeight;
      } else if (NS4) {
            value = document.layers[layer].document.height;
      } else if (Opera56) {
            value = document.getElementById(layer).style.pixelHeight;
      } else {      // IE4 IS SIMPLY A BASTARD !!!
            if (document.all["IE4" + layer]) {
                  layer = "IE4" + layer;
            }
            value = document.all[layer].offsetHeight;
      }
      return (value);
}

function getWindowWidth() {
      var value = 0;
      if ((DOM && !IE) || NS4 || Konqueror || Opera) {
            value = top.innerWidth;
//      } else if (NS4) {
//            value = document.width;
      } else {      // IE
            if (document.documentElement && document.documentElement.clientWidth) {
                  value = document.documentElement.clientWidth;
            } else if (document.body) {
                  value = document.body.clientWidth;
            }
      }
      if (isNaN(value)) {
            value = top.innerWidth;
      }
      return (value);
}

function getWindowXOffset() {
      var value = 0;
      if ((DOM && !IE) || NS4 || Konqueror || Opera) {
            value = window.pageXOffset;
      } else {      // IE
            if (document.documentElement && document.documentElement.scrollLeft) {
                  value = document.documentElement.scrollLeft;
            } else if (document.body) {
                  value = document.body.scrollLeft;
            }
      }
      return (value);
}

function getWindowHeight() {
      var value = 0;
      if ((DOM && !IE) || NS4 || Konqueror || Opera) {
            value = top.innerHeight;
      } else {      // IE
            if (document.documentElement && document.documentElement.clientHeight) {
                  value = document.documentElement.clientHeight;
            } else if (document.body) {
                  value = document.body.clientHeight;
            }
      }
      if (isNaN(value)) {
            value = top.innerHeight;
      }
      return (value);
}

function getWindowYOffset() {
      var value = 0;
      if ((DOM && !IE) || NS4 || Konqueror || Opera) {
            value = window.pageYOffset;
      } else {      // IE
            if (document.documentElement && document.documentElement.scrollTop) {
                  value = document.documentElement.scrollTop;
            } else if (document.body) {
                  value = document.body.scrollTop;
            }
      }
      return (value);
}
0
hankknight
Asked:
hankknight
1 Solution
 
sajuksCommented:
//Can you post your whole code ?
You have not shown where you are getting the browser version code . Thats why u r getting the error For DOM/Opera...

  this.ver=navigator.appVersion
  this.agent=navigator.userAgent
  this.dom=document.getElementById?1:0
  this.opera5=this.agent.indexOf("Opera 5")>-1
  this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
  this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
  this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
  this.ie=this.ie4||this.ie5||this.ie6
  this.mac=this.agent.indexOf("Mac")>-1
  this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
  this.ns4=(document.layers && !this.dom)?1:0;
  this.bw=(this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5)
  return this
}

0
 
sajuksCommented:
//was this what you had missed/left out ?

DOM = (document.getElementById) ? 1 : 0;
NS4 = (document.layers) ? 1 : 0;
Konqueror = (navigator.userAgent.indexOf("Konqueror") > -1) ? 1 : 0;
Konqueror21 = (navigator.userAgent.indexOf("Konqueror 2.1") > -1 || navigator.userAgent.indexOf("Konqueror/2.1") > -1) ? 1 : 0;
Konqueror22 = (navigator.userAgent.indexOf("Konqueror 2.2") > -1 || navigator.userAgent.indexOf("Konqueror/2.2") > -1) ? 1 : 0;
Konqueror2 = Konqueror21 || Konqueror22;
Opera = (navigator.userAgent.indexOf("Opera") > -1) ? 1 : 0;
Opera5 = (navigator.userAgent.indexOf("Opera 5") > -1 || navigator.userAgent.indexOf("Opera/5") > -1) ? 1 : 0;
Opera6 = (navigator.userAgent.indexOf("Opera 6") > -1 || navigator.userAgent.indexOf("Opera/6") > -1) ? 1 : 0;
Opera56 = Opera5 || Opera6;
IE = (document.all) ? 1 : 0;
IE4 = IE && !DOM;
0
 
PeterCNCommented:
layer should be a string, representing an ID attribute of a htmlElement in your page.
For instance, with:

<div id="test">
   test
</div>

you'd have to call the setLeft function like:

setLeft("test", 123);

Where did you get this script? because it contains code for IE4 and Netscape4, which is basically outdated. All modern browsers suppert the document.getElementById stuff etc.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
hankknightAuthor Commented:
Thanks.  I'd post the code, but there are five .js libraries, it is a HUGE project.  Maybe it is time to look for something newer . . .

Anyway, it works, but it just gives the error.  

Is there a way to "supress" JS errors, so the errort doesn't show up in the browser?
0
 
searlasCommented:

Yes,

try { document.getElementById(layer).style.left = x + "px"; } catch (ignore) {}
0
 
dakydCommented:
The "invalid argument" bit makes me think that x isn't an integer or a string of integers.  Most likely, x is "undefined" or else it is something like "25px" and you're adding another "px" to the end of it.  The simple way of testing that is to put an alert(x) right before the line that errors out.  Of course, the question then becomes how are you calling setLeft()?  Hope that helps.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now