floatingDivs 21 Junior Poster

Hey guys,

I've spent the last 20 or so minutes developing an OOP cookie-setting script. Unfortunately, even though everything I'm printing out via alert looks correct, the cookie won't set.

Can someone take a look and see where I've made a mistake?

<script type="text/javascript">			
	function Cookie(){
		this.cookieName;
		this.cookieExpiration;
		this.cookiePath;
		this.cookie;
		
		this.setName = function(name, value){
			this.cookieName = name + '=' + value + '; ';
			return this; 
		}
		
		this.setExpirationDate = function(){
			var date = new Date();
			date.setTime(date.getTime());
			this.cookieExpiration = 'expires=' + date.toGMTString() + '; ';
			return this;
		}
		
		this.setPath = function(path){
			this.cookiePath = 'path=/';
			
			return this;
		}
		
		this.createCookie = function(){		
			alert("'" + this.cookieName + this.cookieExpiration + this.cookiePath + "'");			
			this.cookie = "'" + this.cookieName + this.cookieExpiration + this.cookiePath + "'";
			document.cookie = this.cookie;
			alert(document.cookie);
		}
	}
	
	var cookie = new Cookie();
	cookie.setName('name1', 'val1').setExpirationDate().setPath().createCookie();
</script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.