Using Cookies for User Configurations

<% @ Language="JavaScript" %>

<%

var strGraphCap = "hi";
var strUsername = "";

// CONTENT_LENGTH will only be > 0 if the FORM was submitted using the POST Method
if (Request.
ServerVariables("CONTENT_LENGTH")) {
    strGraphCap = Request("Graphics"); // assign the "Graphics" value to strGraphCap
    strUsername = Request("UserName");

    // Create the UserInformation with the key UName to equal strUsername
    Response.Cookies("UserInformation")("UName") = strUsername;
    Response.Cookies("UserInformation")("GraphCap") = strGraphCap;
}

%>

<HTML>
<HEAD><TITLE>
Cookies for Configuration</TITLE></HEAD>

<BODY>

<%

// if the Cookie UserInformation with the key UName exist
if (Request.
Cookies("UserInformation")("UName")) {
   
// assign the cookie UserInformation with the key UName to strUsername
    strUsername = Request.Cookies("UserInformation")("UName");
    strGraphCap = Request.Cookies("UserInformation")("GraphCap");

    Response.write("Welcome back " + strUsername + "!<P>");
    Response.write('Cookie "UserInformation" = ');
   
// write out the cookie UserInformation with its keys UName & GraphCap
    Response.write(Request.Cookies("UserInformation"));
}

var chkArr = new Array();

// switch statement similar to if - else if - else
switch(strGraphCap) {
   
// if strGraphCap == "lo" then the radio btn "lo" is CHECKED while the other btns are not
    case "lo":
        chkArr[1] = "CHECKED";
        chkArr[2] = "";
        chkArr[3] = "";
        break;
    case "md":
        chkArr[1] = "";
        chkArr[2] = "CHECKED";
        chkArr[3] = "";
        break;
    case "hi":
        chkArr[1] = "";
        chkArr[2] = "";
        chkArr[3] = "CHECKED";
        break;
}

%>

ACTION = Request.ServerVariables("SCRIPT_NAME") equals the name of the page itself so the CGI is the page itself. This means if you decide to rename the page you don't need to alter the ACTION part.
<FORM
ACTION="<% = Request.ServerVariables("SCRIPT_NAME") %>" METHOD="POST">

Graphics Capability:

chkArr[x] checks one the Graphics radio btns based on the switch statement above.
<INPUT
TYPE="radio" <% = chkArr[1] %> NAME="Graphics" VALUE="lo">Low
<INPUT
TYPE="radio" <% = chkArr[2] %> NAME="Graphics" VALUE="md">Medium
<INPUT
TYPE="radio" <% = chkArr[3] %> NAME="Graphics" VALUE="hi">High

Your name:
strUsername is passed through the POST back to itself
<INPUT TYPE="text" NAME="UserName" VALUE="<% = strUsername %>" SIZE="20">
<INPUT
TYPE="submit" NAME="Submit">

</FORM>

</BODY>
</HTML>