/    Sign up×
Community /Pin to ProfileBookmark

popup for cookie that says you’ve already entered your information

I am having a problem with getting a popup if someone has already entered their information on the website. I don’t have noob in the title, but I am. Looking to see what I am doing wrong. Thank you, here is the JavaScript that I’m having issues with: (I am not familiar with posting, so don’t know where the area I’m suppose to put my code)

<code>

<!–

function getCookie(name) {
var results = document.cookie.indexOf(name + “=”);
var len = sPos + name.length + 1;
if((!sPos) && (name != document.cookie.substring(0, name.length))){
return null;
}
if(name == -1){
alert(“You have already submitted your information. Thank you.”);
}
if(address == -1){
alert(“You have already submitted your information. Thank you.”);
}
if(email == -1){
alert(“You have already submitted your information. Thank you.”);
}

var ePos = document.cookie.indexOf(‘;’, len);
if(ePos == -1) ePos = document.cookie.length;
return unescape(document.cookie.substring(len, ePos));
}

function setCookie(name, value, expires, path, domain, secure){
var today = new Date();
if(expires){
expires = expires * 1000 * 3600 * 24;
}
document.cookie = name+’=’+escape(value) +
((expires) ? ‘;expires=’ + new Date(today.getTime() + expires).toGMTString() : ”) +
((path) ? ‘;path=’ + path : ”) +
((domain) ? ‘;domain=’ + domain : ”) +
((secure) ? ‘;secure’ : ”);
}

function deleteCookie(name, path, domain){
if(getCookie(name)){
setCookie(name, ”, -30, path, domain);
}
}
function testFunction(){
var c = parseInt(getCookie(‘Value’));
if(!c){
alert(‘No initial ValuenSetting New CookienValue : 0’);
setCookie(‘Value’, 1);
}else{
alert(‘Stored CookienValue : ‘ + c);
alert(‘Setting New CookienValue : ‘ + (c + 1));
setCookie(‘Value’, (c + 1));
}
deleteCookie(‘Value’);
}
//–>

</code>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledSep 28.2008 — honestly, your code seem to me quite crazy, or code is incomplete. for example, what is [B]sPos[/B] variable? the same apply for [b]email[/b] and [B]address[/B] variable. then, you compare if [b]name[/b] is equal to [b]-1[/b], [u]but[/u] before the comparison you don't set anything to [b]name[/b] variable. so, i assume, initially the variable [b]name[/b] is a string. therefore [b]name[/b] will never match as [b]-1[/b] (unless you strictly pass that string when calling the function). have not read the rest of code, can't say they are fine.

however, i would suggest you to look for already written library for cookie management. if you want to write your own code, for me is ok. just fix those problem, give us more detail, or post the whole code you have.
×

Success!

Help @dgr62679 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.25,
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,
)...