Click to See Complete Forum and Search --> : Setting cookies in XML


rjoseph
09-27-2007, 06:11 AM
Hi Guys

I think I have a really easy one for you.

I am currently using the following script to store information in cookies:

-------------SCRIPT--------------
<%
response.cookies("prefs")("make")="Aston Martin"
response.cookies("prefs")("model")="Vanquish"
response.cookies("prefs")("price")="£40000"
For Each cookie in Response.Cookies
Response.Cookies(cookie).Expires = now()+365
Next
%>
-------------END-------------

This works just fine in my ASP pages but now I need to incorporate the same method into some xml pages and therefore believe I need to use Javascript. I have spent hours reading numerous (how to set cookies in Javascript) articles and have not found a simple example that matches what I want to achieve above.

Can anyone please put me out of my misery and provide me with a simple piece of code that I can use in my xml page to achieve the above?

If so, then that would be great.

I look forward to hearing from you

Rod from the UK

NogDog
09-28-2007, 12:33 AM
Or use an ASP page to serve up your XML document.

rjoseph
09-29-2007, 03:07 AM
Hi NogDog

Thank you for your reply.

unfortunately, this is not an option for me.

I have been on this all day now and haven't got anywhere near doing what I want to achieve. I must of visited every possible website (including w3schools & irt.org) with articles devoted to Javascript cookies and none of them show examples of what I want to achieve. Instead they use what seems as over complicated scripting using <form> input in their examples. Everything is so much more simple in ASP! I have also asked this question to around 10 different message boards and no-one has come anywhere near to helping me out.

I fully understand that people are not obliged to spoon feed me but if the experts can only suggest I read articles then I don't think I have a chance. Unless I get a sudden burst of inspiration I think I'm going to have to give this one up.

Thanks anyway

Rod from the UK

NogDog
09-29-2007, 06:33 AM
A XML document by itself cannot run any client-side scripts. The only way I can think of without the use of server-side scripting would be to use XSLT (that's your search term) for converting your XML data into XHTML output, at which point you could include a <script> block in the output with the desired JavaScript code to set/read cookies.

rjoseph
09-29-2007, 11:12 AM
Hi

Thanks for your reply

This is exacty what I am looking to do. However, I still need to create the necessary Javascript which will enable me to store the cookies.

Any ideas?

Rod from the UK

NogDog
09-29-2007, 04:30 PM
I haven't used JS for cookies in years (I'm a server-side PHP sort of guy), but this article (http://www.quirksmode.org/js/cookies.html) looks decent, and provides some ready-made functions to simplify life a bit for you.