View Full Version : Username Cookie help

06-23-2009, 04:15 AM
So I've spent quite a while looking at this with a puzzled expression and come to the conclusion that I'd be better off asking someone for help and going to bed while waiting..

The code is all located below, basically what I want to happen is have the document write the form and have the input box and submit do the job of the prompt box
WARNING: the prompt that you'll see will save a cookie named c_name

Thanks for any help you may be able to offer, I'm stumped (To quote Stephen K Amos, I'm a "Jack of all trades, Master of **** all")

<script type="text/javascript">
function getCookie(c_name)
if (document.cookie.length>0)
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1)
c_start=c_start + c_name.length+1 ;
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end));
return ""

function setCookie(c_name,value,expiredays)
var exdate=new Date();
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toGMTString());

function checkCookie()
if (username!=null && username!="")
alert('Welcome again '+username+'!');
username=prompt('Please enter your name:',"");
if (username!=null && username!="")

<style type="text/css">
input.name {color:#CCCFFF;}
<body onLoad="checkCookie()">

<form name='name'>
What's your name?
<input type="text" id="cartId" value="Joobleblob Doe" onclick="this.value='';this.onclick=null;" class="name"><br>
<input type='submit' value='Submit' />