Page 1 of 2

JS "object expected" error (possibly on getElement

Posted: Thu Jul 26, 2007 3:58 pm
by UrButtFullOfArr0ws
I get the object expected error in 2 different pages, and the only common thing i can see is the use of getElementById() function...
Can anyone see any flaw in the code, couse i can't see it ? :?
Also the below section is the ONLY js code in the page.

Code: Select all

function showbody(body){
	var number1
	var number2
	document.getElementById(body).style.display = "block"
	If (body == "body1"){
		number1 = "body2"
		number2 = "body3"
	}
	If (body == "body2"){
		number1 = "body1"
		number2 = "body3"
	}
	If (body == "body3"){
		number1 = "body1"
		number2 = "body2"
	}
	document.getElementById(number1).style.display = "none"
	document.getElementById(number2).style.display = "none"
}
The function is called from an external menu which works flawlessly
Can anyone enlighten me? :D

Posted: Thu Jul 26, 2007 4:02 pm
by miro_igov
I always suggest using code coloring editors in such cases. I use Dreamweaver CS3 and when i paste your code in it i see that 'body' word is colored like an object (in purple color) so i assume it is reserved word. Try changing it.

Posted: Thu Jul 26, 2007 4:07 pm
by UrButtFullOfArr0ws
Nope, not working...
And i'm using Crimson Editor, but syntax is set to HTML as i'm in an html document 8)
Body doesn't appear colored on CE, but i changed to i.e. mainbody, and no change.
Any other ideas?

Posted: Thu Jul 26, 2007 4:16 pm
by UrButtFullOfArr0ws
Also here's a general idea of the same code BUT which works:
http://www.manifestinteractive.com/usen ... e_div.html

Anyway, off to sleep now.

Posted: Thu Jul 26, 2007 4:24 pm
by miro_igov
Did you changed the .......id="mainbody"..... ?

Post the changed code please.

Posted: Fri Jul 27, 2007 3:41 am
by UrButtFullOfArr0ws
8O

Wherever there was "body" i changed it to "mainbody" INCLUDING the id on the div element ....
I've also tried using 2 variables instead of 1, of course to no avail

Code: Select all


function showbody(mainbody){
	var number1
	var number2
	if(document.getElementById){
	var a = document.getElementById(mainbody)
	a.style.display=(a.style.display!="none")?"none":"block"
}
	If (mainbody == "body1"){
		number1 = "body2"
		number2 = "body3"
	}
	If (mainbody == "body2"){
		number1 = "body1"
		number2 = "body3"
	}
	If (mainbody == "body3"){
		number1 = "body1"
		number2 = "body2"
	}
	var b = document.getElementById(number1)
	var c = document.getElementById(number2)
	b.style.display = "none"
	c.style.display = "none"
}
But i'm pretty sure that isn't the problem, becouse as i've said, i get the same error on a different page and i'm sure the id i used isn't reserved.

Posted: Fri Jul 27, 2007 4:08 am
by miro_igov
WTH is this If () statement? It must be if().

Also why you hesitate to post all the code including the html?

Posted: Fri Jul 27, 2007 5:42 am
by UrButtFullOfArr0ws
:? :? 8O 8O

What's the freaking point to post HTML code when it's only a div geeze....
If u want it so badly here:

Code: Select all

<body onload="showbody(body1)">

<div style="position: absolute; width: 768px; height: 555px; z-index: 1; left: 10px; top: 15px; background-image:url('images/spacer.jpg'); background-repeat:repeat-y" id="main">
	<div style="position: absolute; width: 445px; height: 36px; z-index: 2; left: 0px; top: 81px" id="menu">
<script menumaker src="abstractshapes.js"></script></div>
	<div style="position: absolute; width: 767px; height: 80px; z-index: 1; left: 0px; top: 0px; background-image: url('images/header.jpg'); background-repeat: no-repeat" id="header">
<div style="position: absolute; width: 245px; height: 57px; z-index: 1; left: 2px; top: 1px" id="animation">
	<img border="0" src="images/animation.gif" width="381" height="76"></div>
&nbsp;</div>
	<div style="position: absolute; width: 445px; height: 436px; z-index: 3; left: 0px; top: 118px; background-image:url('images/background.jpg'); background-repeat:no-repeat; background-position-y:bottom; display:none" id="body1">
ABOUT US TEXT</div>
	<div style="position: absolute; width: 445px; height: 436px; z-index: 3; left: 0px; top: 118px; background-image:url('images/background.jpg'); background-repeat:no-repeat; background-position-y:bottom; display:none" id="body2">
PLACES OF INTEREST TEXT</div>
	<div style="position: absolute; width: 445px; height: 436px; z-index: 3; left: 0px; top: 118px; background-image:url('images/background.jpg'); background-repeat:no-repeat; background-position-y:bottom; display:none" id="body3">
CONTACT ME TEXT</div>
	<div style="position: absolute; width: 321px; height: 473px; z-index: 4; left: 446px; top: 81px" id="images">
<img border="0" src="images/image1.jpg" width="168" height="261"></div>
	<p>&nbsp;</div>
</body>
</html>
Go figure... >.>
And the if statement didn't change anything :?
All the JS buttons on the menu got link to "javascript:showbody(body1)", "javascript:showbody(body2)", "javascript:showbody(body3)"

Posted: Fri Jul 27, 2007 6:56 am
by miro_igov
Silly you, of course i immediately seen your issue from the source.

WTH is

Code: Select all

<body onload="showbody(body1)">
maybe you mean

Code: Select all

<body onload="showbody('body1')">
:idea:

Posted: Fri Jul 27, 2007 6:57 am
by miro_igov
And trust me If () is wrong in javascript, if() is correct. Try it.

Posted: Fri Jul 27, 2007 8:13 am
by UrButtFullOfArr0ws
1) I never said If() was correct...read up. I already knew that but i'm used to case-insensitivity in php :?
2) If you had known from the beggining why let me go through all of this and not suggest it? :?
3) Yeah it solved it ....thanks :)

Posted: Fri Jul 27, 2007 8:31 am
by miro_igov
How the hell i can know it without to see your HTML code which you so furious hide from me :) ?
What's the freaking point to post HTML code when it's only a div geeze....

Posted: Fri Jul 27, 2007 8:52 am
by JayBird
Put the handbags down ladies Image

Posted: Fri Jul 27, 2007 8:53 am
by superdezign
UrButtFullOfArr0ws wrote:What's the freaking point to post HTML code when it's only a div geeze....
Javascript is completely dependent on the HTML that it alters. Without anything to alter, your JavaScript would be doing nothing. When you write code that alters HTML, the HTML is just as important as the code.

Let's not be so hostile.

Posted: Fri Jul 27, 2007 10:38 am
by UrButtFullOfArr0ws
JayBird wrote:Put the handbags down ladies Image
:lol: :lol:
miro_igov wrote:How the hell i can know it without to see your HTML code which you so furious hide from me ?
Well you said that you knew immediately what my issue was ^_^
superdezign wrote:Javascript is completely dependent on the HTML that it alters. Without anything to alter, your JavaScript would be doing nothing. When you write code that alters HTML, the HTML is just as important as the code.

Let's not be so hostile.
:? :? I knew that :D

And i didn't start the hostilities... he started every post with WTF or WTH... how could i respond to that? :roll: