homepage Welcome to WebmasterWorld Guest from 54.226.191.80
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Javascript Cookie Help
BlackRaven




msg:3344471
 7:59 am on May 20, 2007 (gmt 0)

I want the script to do the following

1) Get postid through voting function
2) Check to see if the cookie voteids exists
3) If not create cookie voteids with a value of postid with a underscore char
4) if cookie does exit add postid with underscore after the current cookie value

function voting(postid)
{

if (document.cookie.length > 0)
{
var begin = document.cookie.indexOf(voteids+"=");
if ( begin!= -1)
{
begin += voteids.length+1;
var end = document.cookie.indexOf(";", begin);
if (end == -1)
{
end = document.cookie.length;
}
var ids=document.cookie.substring(begin, end);
ids +=postid+"_";
document.cookie = "voteids="+ids+"_";
}
else
{
document.cookie = "voteids="+ids+"_";
}

}
else
{
document.cookie = "voteids="+ids+"_";
}

}

 

Logician




msg:3356811
 5:49 pm on Jun 2, 2007 (gmt 0)

This should do the job, and ignore duplicates:

function voting(postid)
{
 var cv, dup=false;

 if(document.cookie && (cv=document.cookie.match(/voteids=([^;]+);*/i)) )
  if(cv[1].match(new RegExp('_?'+postid+'([_;]¦$)')))
   dup=true;
 if(!dup)
  document.cookie='voteids='+(cv?cv[1]+'_'+postid:postid);
}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved