/    Sign up×
Community /Pin to ProfileBookmark

I am having trouble with this code as right now neither image is showing, although I think I am very close with the code. Can someone see what I’ve done wrong?

<HTML>
<HEAD>
<TITLE>New Wave Furniture</TITLE>
<SCRIPT LANGUAGE=”JAVASCRIPT”>
<!–Hide from old browsers

function addCookie(tag, value) {
var expireDate = new Date()
var expireString = “”
expireDate.setTime(expireDate.getTime() + (1000 * 60 * 60 * 24 * 365))
expireString = “expires=” + expireDate.toGMTString()
document.cookie = tag + “=” + escape(value) + “;” + expireString + “;”
}

function getCookie(tag) {
var value = null;
var myCookie = document.cookie + “;”
var findTag = tag + “=”
var endPos

if (myCookie.length > 0) {
var beginPos = myCookie.indexOf(findTag)
if (beginPos != -1) {
beginPos += findTag.length
endPos = myCookie.indexOf(“;”, beginPos)
if (endPos == -1)
endPos = myCookie.length
value = unescape(myCookie.substring(beginPos, endPos))
}
}
return value
}

var CookieValue = 0
CookieValue= getCookie(“VisitNumber”)
if (CookieValue != null) {
CookieValue = parseInt(CookieValue) +1
}
else {
CookieValue = 1
}
addCookie(“VisitNumber”, CookieValue)

//–>
</SCRIPT>
</HEAD>
<BODY BGCOLOR=”WHITE” TEXT=”#00384A”>
<TABLE WIDTH=100% BORDER=0>
<TR><TD ALIGN=LEFT>
<IMG SRC=”chair.gif”>
</TD>
<TD ALIGN=RIGHT>
<IMG SRC=”living.gif”>
</TD></TR>
</TABLE>
<H2 ALIGN=”CENTER”><FONT COLOR=”darkblue”>New Wave Furniture</FONT></H2>
<CENTER>
Welcome to our Web page
<BR>
<SCRIPT LANGUAGE=”JAVASCRIPT”>
<!–Hide from old browsers

var CookieValue= “”

CookieValue = getCookie(“VisitNumber”)
if(CookieValue != null) {
if(CookieValue == 1) {
document.write(“<img src=newwave1.gif>”)
}

if (CookieValue == 5) {
document.write(“<img src=newwave5.gif>”)
addCookie(“VisitNumber”, 1)
}

}
//–>
</SCRIPT>
</CENTER>
</BODY>
</HTML>

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@PSLohFeb 22.2005 — wat value do u get if u alert CookieValue???
Copy linkTweet thisAlerts:
@PittimannFeb 22.2005 — Hi!

The way you are dealing with the cookie value, the first image can only show up a single time (first visit). The other one will show up during the 5th visit, the cookie value will be reset to one, on the 6th visit it will be incremented by 1 (new value=2 thus: no image), it will show up again during the 9th visit etc...

In this bit of your code:

if (CookieValue == 5) {

document.write("<img src=newwave5.gif>")

addCookie("VisitNumber", 1)

}

you will need to reset the value to 0 instead of 1, so that when the user comes back next time, the value will be 1 because of the incrementing.

Cheers - Pit
Copy linkTweet thisAlerts:
@kornkob_73authorFeb 22.2005 — I have tried this but my problem is no picture is showing at all.
Copy linkTweet thisAlerts:
@PittimannFeb 22.2005 — Hi!

Assuming that you have cookies enabled:

Your script does not show an image everytime you go to the page. You will need to refresh the page a couple of times. Could also be helpful to delete the cookie before continuing to look for a picture which isn't displayed (then you can count your refreshes).

Cheers - Pit
Copy linkTweet thisAlerts:
@PittimannFeb 22.2005 — Hi!

Do you see images [URL=http://www.pit-r.de/scripts/displayImageDependingOnCookie.htm]here[/URL]? It is your code, except that I stripped out your HTML and that it will display different images for cookie values from 1 to 5.

Cheers - Pit
Copy linkTweet thisAlerts:
@kornkob_73authorFeb 23.2005 — thanks pitt but i really dont understand, maybe i am just off it. I need it to be one picture consistently until the 5th viewing of the page, when then a seperate picture is displayed for the remainder of viewings. Rather than a cycle between many pictures. If you know what I mean could you please help again.
Copy linkTweet thisAlerts:
@kornkob_73authorFeb 23.2005 — does anyone know? please?
Copy linkTweet thisAlerts:
@PittimannFeb 23.2005 — Hi!

I made the little modifications and uploaded the stuff [URL=http://www.pit-r.de/scripts/displayImageDependingOnCookieNew.htm]here[/URL]. Please note: I renamed the cookie to have its' value start from zero again.

Cheers - Pit
Copy linkTweet thisAlerts:
@kornkob_73authorFeb 24.2005 — thanks so much!
Copy linkTweet thisAlerts:
@PittimannFeb 24.2005 — Hi!

You're welcome.

Cheers - Pit
×

Success!

Help @kornkob_73 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.12,
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,
)...