View Single Post
Old 12-08-2012, 06:32 PM   PM User | #1
hcrosex3
New Coder

 
Join Date: Sep 2012
Posts: 32
Thanks: 10
Thanked 0 Times in 0 Posts
hcrosex3 is an unknown quantity at this point
Delete all cookies?

I currently have a function to expire the cookie when the user logs off. As of now it is not is not expiring the cookie any suggestions?

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);
      document.cookie="Vln=" + this.value;
         document.getElementById('txt').style.visibility= 'hidden'; 
         document.getElementById('button').style.visibility= 'visible'; 



    return true;
}


/*
Cookies
*/

function ReadCookie()
{
   var allcookies = document.cookie;

   // Get all the cookies pairs in an array
   cookiearray  = allcookies.split(';');
if (allcookies != '') {
   // 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];

      return "VLN:" + value;
   } 
     }

 else {
  return "";
 }      
    
}

function deleteCookie(ReadCookie) {
var exp = new Date(); // create a new Date object
exp.setTime(exp.getTime() - 1); // set it to yesterday!
var cval = "";
document.cookie = allcookies + "=" + cval + "; expires=" + exp.toGMTString();
} // end deleteCookie





Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">




<head>
  <meta charset="UTF-8">

<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>






<body >
	<div id="header"> <h1> Rose Photography</h1> </div>
	<div class="nav">
<ul>
<li><a href="index.htm" >Home</a></li>
<li><a href="About.htm">About</a></li>
<li><a href="contact.htm" >Contact</a></li>
<li><a href="404.htm">Past Bookings</a></li>
</ul>
</div>
<div id="log">
  <script> document.write(ReadCookie());</script> 

</div>
<div id="login"> 
	<input type="text|hidden" id="txt" name="txt"onblur="validateField()" >  
  <button type="button" id="button" name="button" style= "visibility:hidden ;" onclick="deleteCookie()"> Log Off </button> </div> 

  </body>
hcrosex3 is offline   Reply With Quote