|
-
Nov 4th, 2005, 02:12 PM
#1
Thread Starter
Member
Need help with cookies problem please!
Ok i set up an HTML page to set up cookie and delete cookie. I would like to set up another button to get cookie. The following code is what i have. Lets say if someone sends me a cookie i want to be able to type in a variable and click get cookie and have it display the name of the cookie and its contents. Any help would be much appreciated, Thank you
<HTML>
<HEAD>
<SCRIPT LANGUAGE="Javascript">
<!--
function getexpirydate( nodays){
var UTCstring;
Today = new Date();
nomilli=Date.parse(Today);
Today.setTime(nomilli+nodays*24*60*60*1000);
UTCstring = Today.toUTCString();
return UTCstring;
}
function getcookie(cookiename) {
var cookiestring=""+document.cookie;
var index1=cookiestring.indexOf(cookiename);
if (index1==-1 || cookiename=="") return "";
var index2=cookiestring.indexOf(';',index1);
if (index2==-1) index2=cookiestring.length;
return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}
function setcookie(name,value,duration){
cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);
document.cookie=cookiestring;
if(!getcookie(name)){
return false;
}
else{
return true;
}
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<script>
<!--
if(getcookie("visitorname")){
document.write("Welcome "+getcookie("visitorname"));
}
//-->
</script>
<FORM METHOD="GET">
name: <INPUT TYPE="text" NAME="myname" SIZE="10" MAXLENGTH="20">
<INPUT TYPE="submit" NAME="submit1" VALUE="Set Cookie" onclick="setcookie('visitorname',document.forms[0].myname.value,2);">
<INPUT TYPE="submit" NAME="submit2" VALUE="Delete Cookie" onclick="setcookie('visitorname',document.forms[0].myname.value,-1);">
</FORM>
</BODY>
</HTML>
Last edited by noycwild; Nov 9th, 2005 at 11:50 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|