Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with cookies

Status
Not open for further replies.

mmccammon

Programmer
Joined
Mar 30, 2006
Messages
1
Location
US
I'm trying to read a cookie so that if the value of the cookie != neverAgain then open a pop up survey. If it the value of the cookie == neverAgain then do not show the pop up survey.

I create the cookie with an onClick in the pop up survey so that once a user has completed the survey they should not see it again.

Cookie creation code:

function newCookie(name,value) {
var days = 99999;
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=/";
window.close();
}

I use an onLoad in the html body tag to check the value of the cookie. Code that looks at the cookie:

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

function launchSurvey() {
var val = readCookie("SurveyForm");
if (val == "neverAgain") {
this.window.location = "mypage.html";
}
if (val != "neverAgain") {
window.open("survey_form.html","itportalsurvey","width=410,height=520");
}
}

Is the trouble in my if Statements.

Any help would be appreciated.

Thanks

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top