/    Sign up×
Community /Pin to ProfileBookmark

easy javascript problem (newbie)

And here I thought I was getting this javascript thing down. I’m using the following code to access style compenents. Don’t worry about how it’s changing the styles, it’s just that the code itself is faulty. I get a “expected ‘{‘” error, though it looks fine to me. I have an if/else statement nested within another if statement

<script><!–
function auto(){
if (document.getElementById(“movie”).style.display == “none”){
if (document.getElementById(“notice1”).style.display == “block”) {
document.getElementById(“notice1”).style.display = “none”;
document.getElementById(“notice2”).style.display = “block”
} else if (document.getElementById(“notice2”).style.display == “block”) {
document.getElementById(“notice3”).style.display = “block”;
document.getElementById(“notice2”).style.display = “none”
} else {
document.getElementById(“notice1”).style.display = “block”;
document.getElementById(“notice3”).style.display = “none”
}
}
–></script>

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@ExuroAug 31.2004 — If you were to tab your code, you'd be able to see that you were missing one:
<i>
</i>&lt;script type="text/javascript"&gt;
&lt;!--
function auto() {
if (document.getElementById("movie").style.display == "none") {
if (document.getElementById("notice1").style.display == "block") {
document.getElementById("notice1").style.display = "none";
document.getElementById("notice2").style.display = "block";
} else if (document.getElementById("notice2").style.display == "block") {
document.getElementById("notice3").style.display = "block";
document.getElementById("notice2").style.display = "none";
} else {
document.getElementById("notice1").style.display = "block";
document.getElementById("notice3").style.display = "none";
[color=red]}[/color]
}
}
//--&gt;
&lt;/script&gt;

Tabbing your code is a very good programming practice which makes your code [i]much[/i] more readable, and also lessens the chance of missing something such as an ending curly brace. I hope that helps!
Copy linkTweet thisAlerts:
@CharlesAug 31.2004 — *) The "type" attribute is [i]required[/i] with the SCRIPT element.

*) You would be better off changing the "className" than manipulating the styles directly.

*) It is likely that your error is actually higher up in the document. As with a missed closing quote, sometimes it takes a while for the interpreter to realize this kind of error.
Copy linkTweet thisAlerts:
@daprezjerauthorAug 31.2004 — That was so increadibly stupid. Thanks for the tip.
Copy linkTweet thisAlerts:
@ExuroAug 31.2004 — [i]Originally posted by Charles [/i]

*) It is likely that your error is actually higher up in the document. As with a missed closing quote, sometimes it takes a while for the interpreter to realize this kind of error.[/QUOTE]

Using an editor with syntax highlighting makes it very hard to forget to close strings since the entire rest of the line turns red, or green, or bold, or whatever style your particular editor denotes strings with.
[i]Originally posted by daprezjer [/i]

That was so increadibly stupid. Thanks for the tip.[/QUOTE]

You're welcome!
×

Success!

Help @daprezjer 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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