/    Sign up×
Community /Pin to ProfileBookmark

Need another set of eyes to see why this function is undefined

I’m getting an error message that says that my function is null or undefined. I figure it’ something simple, like maybe a ( instead of {, but I can’t seem to find it. Can someone take a quick look? I’m new to js so if it’s something bigger, I apologize.

Here’s the script from the header:

[CODE]<script type=”text/javascript”>
var time = new Date();
var dayNight = time.getHours();

function displayImage() {

if (dayNight >= 9 && dayNight <= 14) {

document.getElementById(“highlights”).src=”http://www.kacvtv.org/rotatorpics/video-contest.jpg”;

}

if (dayNight >= 14 && dayNight <= 17) {

document.getElementById(“highlights”).src=”http://www.kacvtv.org/rotatorpics/video-contest.jpg”;

}

if (dayNight >= 17 && dayNight <= 22 ) {

document.getElementById(“highlights”).src=”http://www.kacvtv.org/rotatorpics/vine.jpg”;

}

else {
document.getElementById(“highlights”).src”http://www.kacvtv.org/rotatorpics/amergrad.jpg”;
}
}

</script>[/CODE]

And from the body:

[CODE]<body onload=”displayImage()”>
<div>
<img id=”highlights” src=”” alt=””/>
</div>
</body>[/CODE]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@cootheadNov 14.2011 — Hi there javascriptnoob7,

the error is a missing "[b]=[/b]" after "[b]src[/b]" here...
[color=navy]else {
document.getElementById("highlights").src"http://www.kacvtv.org/rotatorpics/amergrad.jpg";
}
[/color]

[i]coothead[/i]
Copy linkTweet thisAlerts:
@007JulienNov 14.2011 — If dayNight=14 or 17 this function changes twice the image !

Variant
[CODE]var dayNight = time.getHours()%23,src="http://www.kacvtv.org/rotatorpics/;

if (dayNight<9) src+='amergrad.jpg';
else if (dayNight<14) src+='video-contest.jpg';
else if (dayNight<17) src+='video-contest.jpg'; // the same ?
else src+='vine.jpg';
document.getElementById("highlights").src=src;
[/CODE]
Copy linkTweet thisAlerts:
@JunkMaleNov 14.2011 — OR...
[CODE]h = new Date().getHours()&#37;23;

s="http://www.kacvtv.org/rotatorpics/;

s += (h>=0 && h<=9) ? "amergrad":
(h>9 && h<=14 ) ? "video-contest":
(h>14 && h<=17 ) ? "video-contest":
(h>17 && h<=23 ) ? "vine":"";

s += ".jpg";

document.getElementById("highlights").src=s;[/CODE]

Twist on that.
Copy linkTweet thisAlerts:
@javascriptnoob7authorNov 14.2011 — Ahh jeez....thanks to all of ya'll. It's working now.
×

Success!

Help @javascriptnoob7 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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