/    Sign up×
Community /Pin to ProfileBookmark

night day imagemap?

hi ppl, have a lil problem, dno how to go abt coding my idea:
i have a night day script and want to add a different imagemap to the frontpage of my site depending if it’s night or day? dno if this is possible the way i’m thinkin of it in my mind as the whole screen wud just be one pic with a tiny bit of txt sayin click where-ever.

[CODE]<script language=”JavaScript”>
<!–
var now = new Date( );
var hour = now.getHours( );
if (hour >= 4 && hour <= 16) {
document.bgColor = “#F00000”;
document.fgColor = “#000004”;
document.write(“<img src=”IRISHMAP.jpg”
width=”302″ height=”320″
usemap=”#IRISHMAP”>

<map id=”IRISHMAP” name=”IRISHMAP”>
<AREA SHAPE=”rect” HREF=”SURFPROJECT3.html” COORDS=”75,64,169,100″ ALT=””>
<AREA SHAPE=”rect” HREF=”SURFPROJECT5.html” COORDS=”18,92,86,125″ ALT=””>
<AREA SHAPE=”rect” HREF=”SURFPROJECT4.html” COORDS=”11,190,93,211″ ALT=””>
</MAP>”); [COLOR=”Red”]<< i know there’s a prob with this whole part of code as it’s probs not possible to do it this way,[/COLOR]
document.write(“day”);
}
else {
//document.write(“<img insert image map night here>”);
document.write(“lol”);
}[/CODE]

ne hlp wud b appreciated ? plz dont tell me to research laws on javascript lol. am workin on it atm too

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@astupidnameMay 24.2009 — When you use document.write with long strings, break the strings up as a variable and then write the variable. It's easier to see what's going on, and helps prevent mistakes. And, you must get the quotes right also, the string inside your document.write uses many double quotes " and you had the string wrapped in double quotes also, a syntax error unless you escape the double quotes inside the string. So you should have really had single quotes wrapping the string. Try it like this:

[CODE]<script type="text/javascript">

var now = new Date( );
var hour = now.getHours( );
if (hour >= 4 && hour <= 16) {
document.bgColor = "#F00000";
document.fgColor = "#000004";
var html = '<map id="IRISHMAP" name="IRISHMAP">';
html += '<AREA SHAPE="rect" HREF="SURFPROJECT3.html" COORDS="75,64,169,100" ALT="">';
html += '<AREA SHAPE="rect" HREF="SURFPROJECT5.html" COORDS="18,92,86,125" ALT="">';
html += '<AREA SHAPE="rect" HREF="SURFPROJECT4.html" COORDS="11,190,93,211" ALT=""></MAP>';
html += '<img src="IRISHMAP.jpg" width="302" height="320" usemap="#IRISHMAP">';
document.write(html);
document.write("day");
}
else {
//document.write("<img insert image map night here>");
document.write("lol");
}

</script>[/CODE]
×

Success!

Help @Astereal 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.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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