javascript: annoying problem, cookies

Joined
12 Feb 2006
Posts
17,639
Location
Surrey
ok so first time looking into cookies and at first was all going well until i tried using the cookies for my site and I have acome across a problem that i don't understand why its happening.

bascially i have a load of images stored in an array and i have a load javascript that sorts the images to be displayed 4 at a time and then displays links to another set, with an increase button if there is more to increase, and drecrease if able to decrease the amount.

now this works fine but the trobule i had with it was that if the user refreshed the page the set of images would go back to the start so what i decided to do, though probably will be told there is a better way, was to use cookies to store which set the user is at so if they return in the same session then the set wil be the one they left at.

the cookie works all fine but weirdly when the user returns and there is a cookie, if the user clicks the increase set button rather then going to the next set by adding 4 to the one its at, it adds for the whole number so say the user is viewing image set 3, rather then 3 + 4 which is 7, its "3" + "4" so 34.

no where in my code does it say to add "4" so i have no clue why its doing this, and also the fact that the decrease set is basically the same code except - 4 and still works fine is very odd.

so can anyone shed some light as to why this might be happening?

also is there a better way to do this other then using cookies? i know with php you can set variables in the address bar so like ocuk.com/index.php?imageSet=4 etc. I have googled and find now such thing for javascript but surely there must be something simliar?
 
Back
Top Bottom