Currently when I hit get cookie it tells me that my cookie is undefined. Any suggestions?
Html
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<head>
<script type="text/javascript" src="fadeslideshow.js">
</script>
<link href="stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css" />
<link href="stylesheets/print.css" media="print" rel="stylesheet" type="text/css" />
<!--[if IE]>
<link href="stylesheets/ie.css" media="screen, projection" rel="stylesheet" type="text/css" />
<![endif]-->
<link href='http://fonts.googleapis.com/css?family=Italianno' rel='stylesheet' type='text/css'>
</head>
<script type="text/javascript">
window.onload= text;
var IdAry=['status1'];
</script>
<body >
<div id="header"> <h1> Rose Photography</h1> </div>
<div class="nav">
<ul>
<li><a href="index.htm" >Home</a></li>
<li><a href="gallery.htm">Gallery</a></li>
<li><a href="404.htm" >Contact</a></li>
<li><a href="404.htm">XML</a></li>
</ul>
</div>
<div id="login">
<form name="name" id="vln" action="" method="post" onblur="toMem(this)">
Login: <input type="text|hidden" id="txt" name="txt" >
<input type="button" value="Get Cookie" onclick="ReadCookie()"/>
</form>
</div>
<div class='border-radius-example' id='border-radius'>
<p id="status1">
<span id="span1">Find Out How I Got Into Photography!</span>
<span class="hide">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eu sapien eget justo porta posuere sollicitudin sed orci. Nunc dictum gravida elit, et sodales velit euismod sed. Nulla facilisi. Cras venenatis, libero ut varius adipiscing, mauris diam tristique eros, quis scelerisque justo enim pulvinar enim. Nulla ante mi, dictum et aliquam ut, interdum at leo. Ut imperdiet, mauris vel tempus euismod, purus nibh gravida urna, eget mattis ante mauris a libero. Maecenas malesuada sagittis justo et gravida. Pellentesque porttitor sollicitudin eleifend. Nulla facilisi. Maecenas feugiat laoreet orci, mattis tempus sem fermentum id. Aenean pretium blandit magna, ac ultrices turpis gravida eget. Proin at bibendum nisl. Phasellus aliquam, enim eu semper adipiscing, turpis lacus tristique nulla, tempor auctor magna odio in justo. Vestibulum vitae purus mauris. Morbi ornare enim sit amet ipsum volutpat a luctus metus condimentum. Quisque aliquet nunc et massa aliquam ut pulvinar justo gravida.
</span>
</p>
</div>
</body>
</html>
JS
Code:
/// Validate Field
function catchEvent(eventObj, event, eventHandler) {
if (eventObj.addEventListener) {
eventObj.addEventListener(event, eventHandler, false);
} else if (eventObj.attachEvent){
event = "on" + event;
eventObj.attachEvent(event, eventHandler);
}
}
catchEvent(window,"load", setupEvents);
function setupEvents(evnt)
{
catchEvent(document.getElementById("txt"), "blur", validateField)
}
function validateField ()
{
var val = this.value.replace(/\D/g, "" ); // zap all NON-digit characters
if ( val.length != 7 ) /* then there must be 7 digits exactly */
{
this.value = '';
alert("not a vln");
return false; // ?? may not be needed, can't hurt
}
this.value = val.substr(0,2) + "-" + val.substr(2,2) + "-" + val.substr(4);
return true;
}
/// Text Functions
function text() {
for (var zxc0=0;zxc0<IdAry.length;zxc0++){
var el=document.getElementById(IdAry[zxc0]);
if (el){
el.onmouseover=function() {
changeText(this,'hide','show')
}
el.onmouseout=function() {
changeText(this,'show','hide');
}
}
}
}
function changeText(obj,cl1,cl2) {
obj.getElementsByTagName('SPAN')[0].className=cl1;
obj.getElementsByTagName('SPAN')[1].className=cl2;
}
/*
Cookies
*/
function ReadCookie()
{
var allcookies = document.cookie;
alert("All Cookies : " + allcookies );
// Get all the cookies pairs in an array
cookiearray = allcookies.split(';');
// Now take key value pair out of this array
for(var i=0; i<cookiearray.length; i++){
name = cookiearray[i].split('=')[0];
value = cookiearray[i].split('=')[1];
alert("Key is : " + name + " and Value is : " + value);
}
}
I don't see any code to set the cookie. You have only a function ReadCookie().
It is your responsibility to die() if necessary….. - PHP Manual
So I have cookie set but it does not show up in the text box when the page is returned too. any suggestions?
Code:
/// Validate Field
function catchEvent(eventObj, event, eventHandler) {
if (eventObj.addEventListener) {
eventObj.addEventListener(event, eventHandler, false);
} else if (eventObj.attachEvent){
event = "on" + event;
eventObj.attachEvent(event, eventHandler);
}
}
catchEvent(window,"load", setupEvents);
function setupEvents(evnt)
{
catchEvent(document.getElementById("txt"), "blur", validateField)
}
function validateField ()
{
var val = this.value.replace(/\D/g, "" ); // zap all NON-digit characters
if ( val.length != 7 ) /* then there must be 7 digits exactly */
{
this.value = '';
alert("not a vln");
return false; // ?? may not be needed, can't hurt
}
this.value = val.substr(0,2) + "-" + val.substr(2,2) + "-" + val.substr(4);
document.cookie='"name=" + this.value;expires=Thu, 2 Aug 2013 20:47:11 UTC; path=/'
return true;
}
/// Text Functions
function text() {
for (var zxc0=0;zxc0<IdAry.length;zxc0++){
var el=document.getElementById(IdAry[zxc0]);
if (el){
el.onmouseover=function() {
changeText(this,'hide','show')
}
el.onmouseout=function() {
changeText(this,'show','hide');
}
}
}
}
function changeText(obj,cl1,cl2) {
obj.getElementsByTagName('SPAN')[0].className=cl1;
obj.getElementsByTagName('SPAN')[1].className=cl2;
}
/*
Cookies
*/
function ReadCookie()
{
var allcookies = document.cookie;
alert("All Cookies : " + allcookies );
// Get all the cookies pairs in an array
cookiearray = allcookies.split(';');
// Now take key value pair out of this array
for(var i=0; i<cookiearray.length; i++){
name = cookiearray[i].split('=')[0];
value = cookiearray[i].split('=')[1];
document.getElementById("txt").innerHTML = document.cookie;
}
}