Dynamic Content

In assignment #8, you saw that the current time could be dynamically printed to a web page using scripting. That same information can be used in conjunction with an IF THEN ELSE statement to create a dynamic "phrase" on a page. The "salutation" printed below is based on an IF THEN ELSE statement. If the current time is before noon, say "Good Morning", ELSE say "Good Afternoon".

Good Afternoon

<%
CurrentTime=time()
IF CurrentTime < #12:00# THEN
  response.write "Good Morning"
ELSE
  response.write "Good Afternoon"
END IF
%>

The above script first establishes a variable that equals the current time. This variable is called CurrentTime. The IF statement tests to see if CurrentTime is before noon. The "#" signs around the time indicate "time" data to the server. The "#" signs must be used around a time or date value.

If the time is before noon, the first Response.Write line will be displayed. Response.Write is a method of writing something to the browser from inside a script. The same result could have been displayed by stopping the scripting after the THEN statement, as follows:

<%
CurrentTime=time()
IF CurrentTime < #12:00# THEN
%>

Good Morning

<% ELSE %>

Good Afternoon

<% END IF %>

Sometimes you will not have the option of turning the scripting off, and the Response.Write command must be used. This is the case with the following page.

Rotating Graphics

Home - Server Side Include - Dynamic Text - Rotating Graphics - Re-Direct - CSS