You are viewing a plain-jane printable version of http://CoverYourASP.com/Application2.asp.
See how this was done

 

A simple function to store HTML

In the earlier example of populating a list box from a recordset I created a function to execute the query, and store the HTML in Application variables for easy and very efficient re-use:

// ============================================
// put infrequently changing data into application variables
// ============================================
function GetListFromApp ( sSQL, sName)
{
   var sHTML;

   // connect to database
   DBInitConnection ( );

   // get HTML from Application variable
   // and if empty...
   if ( ! ( sHTML = Application ( sName ) ) )
   {
      //...get records from database
      DBGetRecords ( sSQL );

      // make up HTML <select> tag
      sHTML = '<select name="' +sName + '">';

      while ( !oRecordSet.EOF )
      {
         sHTML += '<option>' + oRecordSet ( 0 ) + '</option>';      
         oRecordSet.moveNext ( );
      }

      sHTML += '</select>';

      // set the Application variable
      Application ( sName ) = sHTML;
   }

   // release database connection
   DBReleaseConnection ( );

   return sHTML;
}

To use it to store a list box containing all your professors names, do this:

// form tag posting to itself
Response.Write ( '<form action="' + Request.ServerVariables ( 'SCRIPT_NAME' ) + '" method="post">' );

// a list box containing professors - only
// does database query once
Response.Write ( 'Department code: ' + GetListFromApp ( 'SELECT Name FROM Professors', 'prof' ) );

Part 3: Counting visits and page views...