/    Sign up×
Community /Pin to ProfileBookmark

Using cookies to score on certificate

Originally Posted by hamster361
I’ve created a quiz and want to add a certificate. I want to take the percentage score and store it in a cookie , so that if they’ve scored about 50%, I could add a certificate button dynamically and get it to redirect to the certificate page.

On the certificate page, I will then use the cookie to get the percentage.

Any ideas about the coding will be much appreciated.

hamster361

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@3pcJan 16.2008 — Hi Hamster, firstly welcome to the WebDeveloper forum.

For a basic understanding of cookies in javascript, have a look at this article:

http://www.quirksmode.org/js/cookies.html

So utilising the functions they have created you could do the following.
[CODE]function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

function eraseCookie(name) {
createCookie(name,"",-1);
}

//Now the code for your application
function calcScore() {
var userScore = null;
//Your code here to calculate what the score is and
//place it in the userScore variable.
createCookie("score", userScore, 1);
}

//Where you need the score just write
readCookie("score");
[/CODE]


Hope that helps.
×

Success!

Help @hamster361 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.16,
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,
)...