runtime error: object required?

D

dubing

Hi,

Our webpage uses the following JavaScript code.

function toggleSubmenu(divId, link)
{
var div = document.getElementById(divId);
div.style.display = (div.style.display == 'block') ? "none" :
"block";
if (link.className == "")
link.className = "tempselected";
else
link.className = "";
}

Launching the page in IE pops up the error:

A runtime error has occurred. Do you wish to debug? Line:188
Error: Object required

The line reporting error is:

div.style.display = (div.style.display == 'block') ? "none" : "block";

The version of IE I tested is 6.0.2900.2180.xpsp-sp2-gdr.050301-1519.

The page does not return any errors in other browsers (e.g. Firefox,
Netscape, etc.)

How should I fix the error?

Any help would be greatly appreciated.

Bing
 
M

Mick White

(e-mail address removed) wrote:

[snip]
A runtime error has occurred. Do you wish to debug? Line:188
Error: Object required

The line reporting error is:

div.style.display = (div.style.display == 'block') ? "none" : "block";

[snip]

Try:
div.style.display=div.style.display=="none"?"":"none";

Mick
 
G

Geoff Cox

Try:
div.style.display=div.style.display=="none"?"":"none";

Mick,

is above short for something else? if yes, could you please spell it
out?!

Thanks

Geoff
 
M

Mick White

Geoff said:
Mick,

is above short for something else? if yes, could you please spell it
out?!
Google: "ternary operator", or "conditional operator".
Mick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top