johnboat
Technical User
- Jun 18, 2008
- 4
Hi, I am a designer with HTML/CSS/some PHP skills but not much Javascript. I was hoping someone could give me some advice on this problem.
Goal: User clicks link ('More Info') that adds text string to a specific cookie. For example, cookie named 'products' has the value 'chair01' appended. Then, when the user is finished looking at products, I want to write out the cookie contents to a contact form.
Research: I have the basic idea working by modifying this tutorial CodePunk. My code at bottom of post.
Problem: I have another cookie my CMS (ExpressionEngine) uses and I don't won't to read/write to that. I am probably overlooking something simple. Also, is there an easy way to write out the cookie contents without the "cookie_name=" part?
Note: This is not an ecommerce system, so it is not important that the contents of this cookie are readable. It really is just an easy way for people to ask for information about a product without having to send multiple contact requests. I like the idea of using a simple cookie because it seems like overkill to use a database and the 4k cookie limit should be more than enough space for this simple application.
Thanks in advance for any help or suggestions.
Goal: User clicks link ('More Info') that adds text string to a specific cookie. For example, cookie named 'products' has the value 'chair01' appended. Then, when the user is finished looking at products, I want to write out the cookie contents to a contact form.
Research: I have the basic idea working by modifying this tutorial CodePunk. My code at bottom of post.
Problem: I have another cookie my CMS (ExpressionEngine) uses and I don't won't to read/write to that. I am probably overlooking something simple. Also, is there an easy way to write out the cookie contents without the "cookie_name=" part?
Note: This is not an ecommerce system, so it is not important that the contents of this cookie are readable. It really is just an easy way for people to ask for information about a product without having to send multiple contact requests. I like the idea of using a simple cookie because it seems like overkill to use a database and the 4k cookie limit should be more than enough space for this simple application.
Thanks in advance for any help or suggestions.
Code:
[blue]Write cookie code:[/blue]
// in Head
<script language="JavaScript">
function set_cookie(){
if (document.cookie && document.cookie != ""){
var old_cookie = document.cookie;
var product = ("chair01<br/>");
document.cookie = old_cookie + escape(product);
}//ends IF
else{
var product = ("chair01");
document.cookie = "products=<br/>" + escape(product);}
}//ends function
function kill_set_cookie(){
var kill_date = new Date("January 1, 1970");
var kill_string = "products=<br />;expires=" + kill_date;
document.cookie = kill_string;
}//ends function
</script>
// end head
// in Body
<a href="javascript:set_cookie()">More info</a>
// end Body
[blue]Read cookie code:[/blue]
// in Head
<script language="JavaScript">
(document.cookie && document.cookie != "")
{var whole_cookie = unescape(document.cookie);
}
</script>
// end head
// in Body
<script language="JavaScript">document.write(whole_cookie);</script>
// end Body