473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Can't Seem to Access Variable from readCookie()..

Okay....now can anyone tell me why my 'document.write' command isn't reading
the variables assigned to the cookie_info object through the readCookie()
function? This is really teeing me off.

Here's my updated code.

<html><head><title>Problem14</title>

<style type="text/css">
#greeting {position:absolute; left;50px; top:100px;}
</style>

<script type="text/javascript">

function readCookie(the_info)
{
if(document.cookie)
{
var the_cookie = document.cookie;
var the_cookie = unescape(the_cookie);

var broken_cookie = the_cookie.split("=");

var the_values = broken_cookie[1];
var separated_values = the_values.split("/");

var broken_info;
var property_value="";//once you split the backslash you need loop
through
// the values and store them in a variable so you
// can reference them later in the code

for (var i=0; i<separated_values.length; i++)
{
var property_value=separated_values[i];
var broken_info = property_value.split(":");
var the_property = broken_info[0];
var the_values = broken_info[1];
the_info[the_property] = the_values;

}
}

// Return the info you got passed
return the_info;
}

function setCookie(){

//Set Up the Date String

var today = new Date();
var the_month = today.getMonth();
var the_day = today.getDate()+2;
var the_year = today.getFullYear();
var mth_list = new Array("January","February","March","April","May"," June",
"July",
"August","September","October","November","Decembe r");
var alpha_mth = mth_list[the_month];
var condensed_date = alpha_mth+" "+the_day+","+the_year;

//Set Up the Time String

var the_time = today.getTime();
var the_secs = today.getSeconds();
var the_time = Math.floor(the_time/60);
var the_mins = toSt(the_time%60);
var the_time = Math.floor(the_time/60);
var the_hours = toSt(the_time%24);
var the_time_string = the_hours+":"+the_mins+":"+the_secs;

//Set Up The Cookie

var the_cookie = "date:condensed_date/time:the_time_string";

//above...forcing it to read the variable..

document.cookie = "my_cookie="+escape(the_cookie);

//Call The Display Function

displayDateTime(condensed_date,the_time_string);

}

function toSt(n) {
var s=""
if (n<10) s+="0"
return s+n;
}

function displayDateTime(date,time){

var the_div=document.getElementById("greeting");
var the_message="Welcome. Today's date is "+date+" and the time is "+time;
var text=document.createTextNode(the_message);
the_div.appendChild(text);

}

var cookie_info = {};
cookie_info = readCookie(cookie_info);

</script></head>

<body onLoad=setCookie();>

<div id="greeting"></div>

<script type="text/javascript">

var the_name=prompt("what's your name","");
alert ("Welcome, "+the_name+" to my page.");

document.write("The last time you were here or the page was updated was on"+
cookie_info["date"]+" at "+ cookie_info["time"]);
</script>

</body>
</html>

--
Message posted via WebmasterKB.com
http://www.webmasterkb.com/Uwe/Forum...cript/200808/1

Aug 22 '08 #1
3 1291
LayneMitch wrote:
>Okay....now can anyone tell me why my 'document.write' command isn't reading
the variables assigned to the cookie_info object through the readCookie()
function? This is really teeing me off.

Here's my updated code.

<html><head><title>Problem14</title>

<style type="text/css">
#greeting {position:absolute; left;50px; top:100px;}
</style>

<script type="text/javascript">

function readCookie(the_info)
{
if(document.cookie)
{
var the_cookie = document.cookie;
var the_cookie = unescape(the_cookie);

var broken_cookie = the_cookie.split("=");

var the_values = broken_cookie[1];
var separated_values = the_values.split("/");

var broken_info;
var property_value="";//once you split the backslash you need loop
through
// the values and store them in a variable so you
// can reference them later in the code

for (var i=0; i<separated_values.length; i++)
{
var property_value=separated_values[i];
var broken_info = property_value.split(":");
var the_property = broken_info[0];
var the_values = broken_info[1];
the_info[the_property] = the_values;

}
}

// Return the info you got passed
return the_info;
}

function setCookie(){

//Set Up the Date String

var today = new Date();
var the_month = today.getMonth();
var the_day = today.getDate()+2;
var the_year = today.getFullYear();
var mth_list = new Array("January","February","March","April","May"," June",
"July",
"August","September","October","November","Decembe r");
var alpha_mth = mth_list[the_month];
var condensed_date = alpha_mth+" "+the_day+","+the_year;

//Set Up the Time String

var the_time = today.getTime();
var the_secs = today.getSeconds();
var the_time = Math.floor(the_time/60);
var the_mins = toSt(the_time%60);
var the_time = Math.floor(the_time/60);
var the_hours = toSt(the_time%24);
var the_time_string = the_hours+":"+the_mins+":"+the_secs;

//Set Up The Cookie

var the_cookie = "date:condensed_date/time:the_time_string";

//above...forcing it to read the variable..

document.cookie = "my_cookie="+escape(the_cookie);

//Call The Display Function

displayDateTime(condensed_date,the_time_string) ;

}

function toSt(n) {
var s=""
if (n<10) s+="0"
return s+n;
}

function displayDateTime(date,time){

var the_div=document.getElementById("greeting");
var the_message="Welcome. Today's date is "+date+" and the time is "+time;
var text=document.createTextNode(the_message);
the_div.appendChild(text);

}

var cookie_info = {};
cookie_info = readCookie(cookie_info);

</script></head>

<body onLoad=setCookie();>

<div id="greeting"></div>

<script type="text/javascript">

var the_name=prompt("what's your name","");
alert ("Welcome, "+the_name+" to my page.");

document.write("The last time you were here or the page was updated was on"+
cookie_info["date"]+" at "+ cookie_info["time"]);
</script>

</body>
</html>
Had to post this as a separate thread..didn't want it to get lost...need
resolution soon. Thanks.

--
Message posted via WebmasterKB.com
http://www.webmasterkb.com/Uwe/Forum...cript/200808/1

Aug 22 '08 #2
Also, can anyone tell me how to get time in the United States with this code?

--
Message posted via WebmasterKB.com
http://www.webmasterkb.com/Uwe/Forum...cript/200808/1

Aug 23 '08 #3
In comp.lang.javascript message <891b7d7daf037@uwe>, Sat, 23 Aug 2008
16:31:06, LayneMitch via WebmasterKB.com <u39402@uwe.?.invalidposted:
>Also, can anyone tell me how to get time in the United States with this code?
Does that mean that it is you or the time that is to be in the United
States? From your previous writings, I'd thought that you were there
already.

Whatever "this code" may be, then that depends on how it's written and
perhaps on where you are. It must depend on whereabouts in the United
States you want, too.

<http://web.archive.org/web/200702022...ering.com/faq/
index.htmlsection 3.2 could have helped you.

Google for JavaScript date and time elsewhere and you get 141,000
pages found; try the first one.

<URL:http://www.merlyn.demon.co.uk/js-date5.htm>

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Aug 24 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jeff | last post by:
I've searched the web for hours trying to figure out this problem and can't seem to find any pertinent answers. I have a website where the user starts on a login page, puts in their credentials and...
3
by: Nelson Broat | last post by:
In jsp land you can have the following: <% String name = "Nelson"; %> Hi, my name is <%= name %>. Such that, in your browser you see:
6
by: Paul | last post by:
Hello everyone: I am developing a VB.Net Windows Application and I am now ready to create the deployment project for it. This application needs to be installable on a different number of users...
11
by: Colleyville Alan | last post by:
I posted that I was having trouble with a SQL statement that was working in the SQL window, but not in VBA. I have since discovered that when I create the string in VBA it is over 1023 characters...
3
by: Ryan Ritten | last post by:
Hey, I just started working at this new company and they gave me a simple database project to start with. yet I am starting to look like an idiot cause I can't even seem to connect to the MS...
73
by: Claudio Grondi | last post by:
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an...
24
by: Paul | last post by:
I am taking over an existing app and having trouble understanding their references. They have encapsulated Pear packages in the directory structure like: /site /site/html/Pear.php...
9
by: LayneMitch via WebmasterKB.com | last post by:
Hello. Got another one for you folks. I'm working on this problem that wants me to 1. Prompt for name 2. Use pop-up box with name 3. Display current date on page in format "October 30, 2000."...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.