Lee-yoshi Posted May 19, 2010 Share Posted May 19, 2010 Hi,This might sound like a stupid question (I'm new to ASP) but is it possible to add to an ASP Cookie through a link? (I.e. Someone clicks on a link, and by clicking that link something is added to the cookie)And if so, how?Many thanks. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 19, 2010 Share Posted May 19, 2010 You can either use Javascript to set a cookie or ASP. If you wanted to use ASP then the page would need to refresh. If you used Javascript you could change the cookie without refreshing the page. Link to comment Share on other sites More sharing options...
Lee-yoshi Posted May 19, 2010 Author Share Posted May 19, 2010 Cool. I think i know how you mean about making the page refreshing using ASP, but just out of curiousity how would you do it with Javascript (If it's easier!)?Thanks. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 19, 2010 Share Posted May 19, 2010 There are some Javascript functions for working with cookies here:http://www.w3schools.com/js/js_cookies.aspYou can attack an onclick handler to any element you want in order to execute some Javascript code when the user clicks on that element. Link to comment Share on other sites More sharing options...
Lee-yoshi Posted May 23, 2010 Author Share Posted May 23, 2010 Thanks justsomeguy, really appreciate the help.I attempted Javascript but i need some ASP related elements within my cookies so i've gone back to ASP again.Is it possible to have a variable property as a name for a cookie? My problem is that i need cookies to hold different numbers, numbers of which i will not know, and of which there may be more than one of (Hence storing another number in another cookie so it is easy to retrieve). The code below works great the first time, the second time there is a problem though, and it's most likely from the line where (NumItems) doesn't have " around it because it's the name of a variable. <%dim NumItemsdim POIDPOID = request.querystring("poid")if( Response.Cookies.Count > 0 ) Then NumItems = Request.Cookies("Amount") NumItems = NumItems + 1 Response.Cookies("Amount") = NumItems Response.Cookies(NumItems)("Item") = POIDelse Response.Cookies("Amount") = 1End if%>... Thanks for any help you can give me. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 23, 2010 Share Posted May 23, 2010 If that doesn't save the cookie, then you might not be able to use a number as the name. You could add a prefix to the beginning of it. Link to comment Share on other sites More sharing options...
Lee-yoshi Posted June 2, 2010 Author Share Posted June 2, 2010 Adding a prefix worked a charm :)Cheers! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.