/    Sign up×
Community /Pin to ProfileBookmark

conflicting scripts

I have two javscripts where one displays the time, and the other uses cookies to store as a notepad. ( I didn’t write these myself)

the clock:
<script> function show2(){
if (!document.all&&!document.getElementById)
return
thelement=document.getElementById? document.getElementById(“clock”): document.all.clock
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
var seconds=Digital.getSeconds()
var dn=”PM”
if (hours<12)
dn=”AM”
if (hours>12)
hours=hours-12
if (hours==0)
hours=12
if (minutes<=9)
minutes=”0″+minutes
if (seconds<=9)
seconds=”0″+seconds
var ctime=hours+”:”+minutes+”:”+seconds+” “+dn
thelement.innerHTML=Digital.getMonth()+”.”+Digital.getDate()+”.”+Digital.getYear()+” | “+ctime
setTimeout(“show2()”,1000)
}
window.onload=show2
</script>

body call:

<div id=”clock”></div>
—————————-

the notes:
<script>

function ReadCookie (Name)
{
var search = Name + “=”
if (document.cookie.length > 0)
{
offset = document.cookie.indexOf(search)
if (offset != -1)
{
offset += search.length
end = document.cookie.indexOf(“;”, offset)
if (end == -1)
end = document.cookie.length
return (document.cookie.substring(offset, end))
}
else
return (“”);
}
else
return (“”);

}

function WriteCookie (cookieName, cookieValue, expiry)
{
var expDate = new Date();

expDate.setTime (expDate.getTime() + expiry);
document.cookie = cookieName + “=” + escape (cookieValue) + “; expires=” + expDate.toGMTString() + “; path=/”;

}

function getCookies()
{
document.noteForm.note.value = unescape(ReadCookie(“note”));
}

</script>

body call:
<script>window.onload=function() { getCookies(); }</script>

I have no problem with the two script seperatly, but when I add the last script into the page, nothing works.
I know this may seem confusing, but is there anything I can change to get them both to work fine?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@havikApr 10.2003 — It's these lines of code that are causing the errors:

the clock:

window.onload=show2

the notes:

<script>window.onload=function() { getCookies(); }</script>

You can't have window.onload declared twice. They need to be together.

Try this:

<script type="text/javascript">

function loadfunctions() {

getCookies();

show2();

}

</script>

<body onload="loadfunctions()">

and remove the other code. If that doesn't work let me know.

Havik
Copy linkTweet thisAlerts:
@obviousunknownauthorApr 11.2003 — That worked perfectly. Thanks for the quick reply. ?
×

Success!

Help @obviousunknown 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.1,
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,
)...