Content Supported by Sourcelens Consulting
<HTML>
<HEAD>
</HEAD>
<BODY bgColor=#ffffff leftMargin=40 link=#500000 vLink=#505050>
<FONT FACE="Verdana, Arial, Helvetica" SIZE=2>
<FONT SIZE=4 COLOR=#500000>Behind the Scenes</FONT>
<BR><BR>
<P>This sample uses one file, Prefer.asp, which creates an
HTML form that posts information back to the same ASP page. When creating a page
to save settings to cookies, you will not generally use this method. Instead,
you would typically use one page to store settings, and use other pages in your
application to read them back. First, this ASP page checks whether the HTML form
has posted back to the ASP page already. If it has, two cookies are written
using server-side Visual Basic, Scripting Edition (VBScript).</P>
<FONT face=Courier>
If Len(Request("BGColor")) > 0
then <BR> Response.Cookies("BGColor")
= Request("BGColor") <BR>
Response.Cookies("FGColor") = Request("FGColor") <BR>
End If
</FONT>
<P>Then, the code checks to see if a cookie called BGColor
has been written out. If there is no cookie, the page has not saved any
preferences and the index of the drop-down boxes should be set to 0. If the
cookies exist, they are read into variables to be placed into client-side
JavaScript.</P>
<FONT face=Courier>
If
Request.Cookies("intBGColor") = "" then <BR> intBG = 0 <BR> intFG = 0 <BR>
Else <BR> intBG =
Request.Cookies("intBGColor") <BR>
intFG = Request.Cookies("intFGColor") <BR>
End If
</FONT>
<P>The BODY tag is used to set the background color and to
call a function to set the index values of the drop-down boxes.</P>
<FONT face=Courier><BODY BGCOLOR=<%=
Request.Cookies("BGColor")%> ONLOAD="setcolor()">
</FONT>
<P>The SetColor function uses JavaScript to set the index
values. The code gets the values from cookies that were read using server-side
VBScript. </P>
<FONT face=Courier>
function setcolor() { <BR> document.Pref.BGColor.selectedIndex =
<%=intBG%>; <BR>
document.Pref.FGColor.selectedIndex = <%=intFG%>; <BR>
}
</FONT>
<P>The foreground color is set using the FONT tag.</P>
<FONT face=Courier><FONT
COLOR=<%=Request.Cookies("FGColor")%>>
</FONT>
<P>The rest of the page creates a form that, when
submitted, will call a function to write the index values of the drop-down boxes
into cookies and post the information back to this same
ASP.</P></FONT>
</BODY>
</html>