Hi, I created this code...it consist of 2 html pages with javascript/cookies. The first one (councilold.htm) contains checkboxes and one editbox. The user is required to enter their name and their favourite pages...when they click submit the cookie is stored and then open a new page (sidebarold.htm).
In page 2 (sidebarold.htm) when it is opened it will display all the values that the user entered in the first page (councilold.htm).
My code is only showing the name of the user entered..not the user's favourtie pages (checkboxes). Please re-check my code for me. Thank you so much!!!
This is all the codes...you may try it!
==========================
==========
==========
==========
=======
PAGE 1: councilold.htm
==========================
==========
==========
==========
=======
<HTML>
<HEAD>
<TITLE>Student Council Preferences</TITLE>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function createCookie(name,value,da
ys)
{
if (days)
{
var date = new Date();
date.setTime(date.getTime(
)+(days*24
*60*60*100
0));
var expires = "; expires="+date.toGMTString
();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function addClub(Clubname, URL, Cookie)
{
this.Clubname = Clubname
this.URL = URL
this.Cookie = Cookie
return this
}
function storeme()
{
var Clubs = new Array(6)
Clubs[0] = new addClub("Alumni Association", "alumni.htm", "interest1")
Clubs[1] = new addClub("Astronomy Club", "astronomy.htm", "interest2")
Clubs[2] = new addClub("Student Government", "studgovt.htm", "interest3")
Clubs[3] = new addClub("Radio and Television Club", "radio.htm", "interest4")
Clubs[4] = new addClub("Intramural Sports", "intramurals.htm", "interest5")
Clubs[5] = new addClub("Scuba Club", "scuba.htm", "interest6")
var flag = 'N';
var chkval = '';
for(i=0;i<6;i++)
{
if(Clubs[i].Cookie)
{
flag='Y';
if(chkval=='')
{
chkval = Clubs[i].Cookie
}
else
{
chkval = chkval + "," + Clubs[i].Cookie
}
}
}
if(flag=='N')
{
alert("Please choose some options")
return false;
}
else
{
return createCookie("myfavsite",c
hkval,"");
}
}
//-->
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFCC" TEXT="#00384A">
<CENTER>
<img src="header1.gif" width="472" height="108">
<p>
<img src="please.gif" width="472" height="55"></p>
</CENTER>
<form NAME="frm" METHOD="post" ACTION="sidebarold.htm" ONSUBMIT="return storeme()">
<CENTER>
<TABLE BORDER=0>
<TR>
<TD>Name: </TD>
<TD><INPUT TYPE="text" SIZE=20 NAME="favedit"></TD>
</TR>
</TABLE>
<BR>
<TABLE BORDER=0 CELLPADDING=2>
<TR>
<TD>Alumni Association</TD>
<TD><input type="checkbox" name="interest1" value="ON"></TD>
<TD WIDTH=50></TD>
<TD>Astronomy Club</TD>
<TD><input type="checkbox" name="interest2" value="ON"></TD>
</TR>
<TR>
<TD>Student Government</TD>
<TD><input type="checkbox" name="interest3" value="ON"></TD>
<TD WIDTH=50></TD>
<TD>Radio and Television Club</TD>
<TD><input type="checkbox" name="interest4" value="ON"></TD>
</TR>
<TR>
<TD>Intramural Sports</TD>
<TD><input type="checkbox" name="interest5" value="ON"></TD>
<TD WIDTH=50></TD>
<TD>Scuba Club</TD>
<TD><input type="checkbox" name="interest6" value="ON"></TD>
</TR>
</TABLE>
<BR>
<INPUT TYPE="submit" NAME="Continue" VALUE="Continue" onclick = "createCookie('myName',doc
ument.frm[
'favedit']
.value,6)"
>
<INPUT TYPE="reset" NAME="Reset" VALUE="Clear All">
</CENTER>
</FORM>
</BODY>
</HTML>
==========================
==========
==========
==========
=======
PAGE 2: sidebarold.htm
==========================
==========
==========
==========
=======
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function addClub(Clubname, URL, Cookie)
{
this.Clubname = Clubname
this.URL = URL
this.Cookie = Cookie
return this
}
function readCookie(name)
{
var nameEQ = name + "=";
var ca = document.cookie.split(';')
;
for(var i=0;i < ca.length;i++)
{
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,
c.length);
}
return null;
}
//-->
var Clubs = new Array(6)
Clubs[0] = new addClub("Alumni Association", "alumni.htm", "interest1")
Clubs[1] = new addClub("Astronomy Club", "astronomy.htm", "interest2")
Clubs[2] = new addClub("Student Government", "studgovt.htm", "interest3")
Clubs[3] = new addClub("Radio and Television Club", "radio.htm", "interest4")
Clubs[4] = new addClub("Intramural Sports", "intramurals.htm", "interest5")
Clubs[5] = new addClub("Scuba Club", "scuba.htm", "interest6")
function setEditMode()
{
var date = new Date();
var expires="";
date.setTime(date.getTime(
) + (1000 * 60 * 60 * 24 * 365))
document.cookie="EditMode=
" + escape("true") + "; expires=" + date.toGMTString() +";"
top.location.href = "council.htm";
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFCC">
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
var cookieValue = readCookie("myName")
if (cookieValue != null)
{
document.write("<TABLE BORDER=0 CEELPADDING=0 CELLSPACING=0 WIDTH=100%>")
document.write("<TR ALIGN=CENTER><TD><B>Clubs of Interest</B></TD></TR>")
document.write("<TR ALIGN=CENTER><TD><B>for</B
></TD></TR
>")
document.write("<TR ALIGN=CENTER><TD><B>" + cookieValue + "</B></TD></TR>")
document.write("</TABLE><B
R>")
}
document.write("<TABLE BORDER=0 CEELPADDING=0 CELLSPACING=12 WIDTH=100%>")
for (var i=0; i<6; i++)
{
Cookiedefined = readCookie(Clubs[i].Cookie
)
if (Cookiedefined != null)
{
if (Cookiedefined == "true")
{
document.write("<TR ALIGN=CENTER><TD><A HREF=" + Clubs[i].URL +" TARGET=LOWERRIGHT>" + Clubs[i].Clubname + "</A></TD></TR>")
}
}
}
document.write("</TABLE>")
</SCRIPT>
<center>
<A HREF="JavaScript:setEditMo
de();"> Change Preferences</A>
</CENTER>
</BODY>
</HTML>
==========================
==========
==========
==========
=======
Sorry my code is such a mess!!! That why I'm here to ask for help!!! Thank you sooo much!
I'm not really good using javascript/cookies
Start Free Trial