/    Sign up×
Community /Pin to ProfileBookmark

can you see why my code using cookies stuffs up?

i have a code at the following address in progress: [URL=http://www.gooba.tk/]www.gooba.tk[/URL] . it uses cookies to store your favourite links in a list for future refference. Now when you use the favourites list, if you add more than 10 or 11 links for some reason they all dissappear and do all sorts of stupid things. why? i hav spent ages trying to fix it but cannot see where the problem is.

i am not asking you to fix it just push me in the correct direction please..

thankyou

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@David_HarrisonMar 24.2004 — I think there is a limit to the number of cookies a user can have on their PC. Instead of creating lots of cookies, create 1 cookie with all of the URL's in. When the URL's are received by the function just do something like this:

<i>
</i>
var cookieString;
var urls=new Array();
urls["href"]=new Array();
urls["text"]=new Array();

function favAdd(){

var newHref=document.forms.favForm.favHrefInput.value;
var newText=document.forms.favForm.favTextInput.value;

if (newHref.length==0) {alert("Please enter the URL (address) of the website."); return false;}
if (newHref.substring(0, 7)!="http://") newHref="http://"+newHref;
if (newText.length==0) newText=newHref.substring(7, newHref.length);
if (newText.length&gt;50) newText=newText.substring(0, 49)+"...";

urls["href"][urls["href"].length]=newHref
urls["text"][urls["text"].length]=newText

cookieString=urls["href"].join("::delim::")+"::spacer::"+urls["text"].join("::delim::");

}

Then you can add the cookieString to your cookie. If you want to retrieve the information from the cookie then you can do this:

<i>
</i>
var temp=new Array();

temp=cookieString.split("::spacer::");

urls["href"]=temp[0].split("::delim::");
urls["text"]=temp[1].split("::delim::");

What the above scripts do is combine all of href's into one array and all of the text's in another array.

When the information is stored in a cookie each array is joined into a single string and each item is separated by "::delim::" then the to arrays are joined together and separated by "::spacer::".

When separating the information out into different arrays again, I have in effect just reversed the process. If you like I could write an actual working script in an HTML document that joins arrays and splits them up again, then you can add the cookie part of the script.
×

Success!

Help @benjamin 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.20,
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,
)...