Jump to content

who wants to eat Cookies??


frozentree

Recommended Posts

i am very confuse at this tutorial lesson bout cookies.. i try creating one but it dint work out...i would like to understand the most simple cookies first then only take a look at w3school example of cookies. i try to understand this

<script language="JavaScript"><!--function set_it(){ var thename= window.prompt("What is your name?",""); var the_text="name="+thename+"&"; var toexpire= new Date("March 15, 2008"); var expdate="expires="+toexpire.toGMTString(); the_text+=expdate;  var newtext=escape(the_text); document.cookie=newtext;}function read_it(){ if (document.cookie) {  var mycookie=document.cookie;  var fixed_cookie= unescape(mycookie);  var thepairs= fixed_cookie.split("&");  var pair1= thepairs[0];  var pair2= thepairs[1];  var namevalue1= pair1.split("="); window.alert("Welcome, "+namevalue[1]+"!"); } else { set_it(); }}read_it();//--></SCRIPT>

this din work..nothing happen when i try 2 examine it... wat is wrong? cant understand cookies at all... would somebody lend me a hand here? thanks

Link to comment
Share on other sites

You are SO close. This:

  var namevalue1= pair1.split("=");  window.alert("Welcome, "+namevalue[1]+"!");

Should be:

  var namevalue1= pair1.split("=");  window.alert("Welcome, "+namevalue1[1]+"!");

You set a variable named "namevalue1", so, when you try to run the alert, you need to reference "namevalue1" rather than "namevalue".

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...