/    Sign up×
Community /Pin to ProfileBookmark

Javascript Errors

Hi, I have got some javascript that toggles between two divs to hide and show each. The only problem is that it shows up an error.

here is the javascript and error message:
JS

[CODE] function switch1(div)
{
if (document.getElementById(‘one’))
{
var option=[‘one’,’two’,’three’];
for(var i=0; i<option.length; i++)
{ obj=document.getElementById(option[i]);
obj.style.display=(option[i]==div)? “block” : “none”; }
}
}[/CODE]

HTML

[CODE] <div id=”one”><ul>

<li><h2><?php _e(‘Categories’); ?></h2></li>

<ul>

<?php wp_list_cats(‘sort_column=name&optioncount=1’); ?>
</ul>

</ul>
</div>
<div id=”two”>
<ul>
<li><h2><?php _e(‘Archives’); ?></h2>

<ul>

<?php wp_get_archives(‘type=monthly’); ?>

</ul>
</li>

</ul>
</div>
</div>[/CODE]

and then the error message:

[COLOR=”Red”]Obj has no properties[/COLOR]

and it effects the line:
[COLOR=”Red”]
obj.style.display=(option==div)? “block” : “none”; }[/COLOR]

If you could help it would be great!

Ricky

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@felgallJul 06.2007 — You are probably running it before all three ids have loaded into the page.
×

Success!

Help @ricky101 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...