JS "object expected" error (possibly on getElement

JavaScript and client side scripting.

Moderator: General Moderators

UrButtFullOfArr0ws
Forum Commoner
Posts: 64
Joined: Wed Feb 21, 2007 11:42 am
Location: Up a tree >.>"

JS "object expected" error (possibly on getElement

Post 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
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post 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.
UrButtFullOfArr0ws
Forum Commoner
Posts: 64
Joined: Wed Feb 21, 2007 11:42 am
Location: Up a tree >.>"

Post 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?
UrButtFullOfArr0ws
Forum Commoner
Posts: 64
Joined: Wed Feb 21, 2007 11:42 am
Location: Up a tree >.>"

Post 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.
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

Did you changed the .......id="mainbody"..... ?

Post the changed code please.
UrButtFullOfArr0ws
Forum Commoner
Posts: 64
Joined: Wed Feb 21, 2007 11:42 am
Location: Up a tree >.>"

Post 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.
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

WTH is this If () statement? It must be if().

Also why you hesitate to post all the code including the html?
UrButtFullOfArr0ws
Forum Commoner
Posts: 64
Joined: Wed Feb 21, 2007 11:42 am
Location: Up a tree >.>"

Post 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)"
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post 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:
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

And trust me If () is wrong in javascript, if() is correct. Try it.
UrButtFullOfArr0ws
Forum Commoner
Posts: 64
Joined: Wed Feb 21, 2007 11:42 am
Location: Up a tree >.>"

Post 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 :)
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post 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....
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Put the handbags down ladies Image
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
UrButtFullOfArr0ws
Forum Commoner
Posts: 64
Joined: Wed Feb 21, 2007 11:42 am
Location: Up a tree >.>"

Post 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:
Post Reply