Jump to content

Expandable Block


Kaoru

Recommended Posts

This one confuses me quite a bit...I've coded an expandable block on my page, and it works fine, but my browser keeps giving me an "object expected" error on the hyperlink.

<a href="#" onclick="expandCollapse([color="#FF0000"]_[/color]'tabInfoBlockID', true); setTabInfo('tabInfoBlockID'); return false;">

I've put a red underscore where the browser tells me the error is.Apparently it's not a fatal error, seeing as the block expands, but since this site is for my business, I'd like to look as professional as possible and having errors popping up doesn't look professional :)

Link to comment
Share on other sites

Does the JS error come up on page load or when you click the link. also post the javascript code [function: expandCollapse].
The error comes up when I click the link. Here's the java script:
function expandCollapse(elem, changeImage){	if (document.getElementById)	{		ecBlock = document.getElementById(elem);		if (ecBlock != undefined && ecBlock != null)		{			if (changeImage)			{				elemImage = document.getElementById(elem + "Image");			}			if (elemImage != undefined && elemImage != null)			{				if (ecBlock.currentStyle.display == "none" || ecBlock.currentStyle.display == null || ecBlock.currentStyle.display == "")				{					ecBlock.style.display = "block";					if (changeImage)					{						elemImage.src = "Images/up.jpg";					}				}				else if (ecBlock.currentStyle.display == "block")				{					ecBlock.style.display = "none";					if (changeImage)					{						elemImage.src = "Images/down.jpg";					}				}				else				{					ecBlock.style.display = "block";					if (changeImage)					{						elemImage.src = "Images/up.jpg";					}				}			}		}	}}

I don't think it's a problem with the JS because the JS is in an external file. The browser reports a the error to be on the .html page.

Link to comment
Share on other sites

Is this page on the Internet? If so, maybe you could provide a link and it'd be easier to determine what the problem is.
I don't have webspace for the site yet, unfortunately. I'm still developing the site and I'm waiting for payment so that I can get webspace.Any ideas so far?A friend said to change the hyperlink to
<a href="java script: expandCollapse('tabInfoBlockID', true);setTabInfo('tabInfoBlockID'); return false;">

but that doesn't do anything (the block doesn't even expand)Then he said:

Change your click on the <a> tag so that you only call one method and there is no need to return false.
I'm not sure what he meant by that, so I haven't done anything (just reset it to the way I had it originally)
Link to comment
Share on other sites

Ok, I managed to fix the problem!Seems that since I'm still relatively new to JS, I wrote the function above to make the block expand. I left out another function that's needed, once I included that, it all works 100%.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...