Guide for Running Studies over the Web with ASP

    The tutorial begins with a demonstration how Active Server Pages (ASP) code is used to manipulate the content within an individual Web page.  Arguably two of the most important elements necessary for an experimental study over the Web are random assignment of conditions and the ability to present the remote participant-client with the correct stimulus materials corresponding to the condition to which he or she has been randomly assigned.  This page describes important elements of how ASP accomplish these tasks.

    The table below represents a 2-by-2-by-2-by-2 factorial between-subjects design.  The variables manipulated are the age (18 or 40) and sex of the defendant, whether he was seen in the area of the crime or had an alibi, and whether he knew the victim or not.  Below the table is printed a random subject number between 1 and 9,999,999, a random condition number between 1 and 16, and the corresponding text for each of the manipulations for that condition.

    Hit "Reload" (or "Refresh") on your browser.  The numbers should change, as should the text to correspond with the new condition number.


  Seen Alibi
Argue No Know Argue No Know
18 Y.O. Male 1 2 3 4
Female 5 6 7 8
40 Y.O. Male 9 10 11 12
Female 13 14 15 16

 

Your subject number is: 2152673

Condition number: 3

Manipulation 1: The defendant, Joe Smith, was 18 years old at the time of the crime.

Manipulation 2: The defendant is a male .

Manipulation 3: The defendant has an alibi for the time of the crime.

Manipulation 4: The defendant was seen arguing with the victim, Frank Jones, the day before in a bar.


    How this is accomplished can be seen in the box below, which gives the HTML code for the present page (up to this point).  The ASP code is displayed between the <% and %> tags, and appears in red, at least in FrontPage.  It is processed on the server before the HTML code (in blue and black) is sent to the client. 

<html>
<
body
>

<%
Randomize
u = Round(Rnd*9999999)
Session("subnum") = u
Randomize
c = Round((Rnd*16 + 0.5))
Session("condition") = c
%>

<p>Your subject number is: <%= Session("subnum") %></p>
<p>
Condition number: <%= Session("condition") %></p>
<p>
Manipulation 1: The defendant, Joe Smith, was
<% IF Session("condition") <= 8 THEN %>
18
<% ELSE %>
40
<% End if %>
years old at the time of the crime.</p>
<p>
Manipulation 2: The defendant is a
<% IF (Session("condition") >= 1 AND Session("condition") <= 4) OR (Session("condition") >= 9 AND Session("condition") <= 12) THEN %>
male
<% ELSE %>
female
<% End if %>
.</p>
<p>
Manipulation 3:
<% IF (Session("condition") Mod 4 = 1) OR (Session("condition") Mod 4 = 2) THEN %>
The defendant was seen in the area 10 minutes after the stabbing.
<% ELSE %>
The defendant has an alibi for the time of the murder.
<% End if %>
</p>
<p>
Manipulation 4:
<% IF Session("condition") Mod 2 = 0 THEN %>
The defendant did not know the victim Frank Jones.
<% ELSE %>
The defendant was seen arguing with the victim, Frank Jones, the day before in a bar.
<% End if %></p>

</body>
</html>

   The key to manipulating content within a page is the Session variable.  Arguably the most valuable tool of the server-side scripting of Active Server Pages is the Session variable.  Each participant that is connected to the server at any given time has a single, unique Session object.  This Session object can store an unlimited number of Session variables that will apply exclusively to one participant.  Most important, the value of the variable is stored on the server, and thus even if the content of the pages is changing the Session variable remains unaltered until either a script changes its value or it expires.  Session variables are defined within ASP code by the command Session("variablename") = value. The value may be either a text string or a numerical value. 

    In the box above, the Session variables called Session("subnum") and Session("condition") are used.  The first section of ASP code assigns a random number between 1 and 9,999,999 to Session("subnum"). The Rnd command in VBScript chooses a random number between 0 and 1; this is multiplied by 9,999,999, and then that result is rounded to the nearest integer with the Round command.  Similarly, a random condition number between 1 and 16 is assigned to Session("condition").  Now, additional code is needed to send the correct HTML code to the client's browser according to the assigned condition number.

    First, the current value of a Session variable can be displayed to the client using the statement: <%= Session("variablename") %>.  This is the same as writing: <% response.write Session("variablename") %>.  Both statement place the value of the Session variable in the place of the statement, and then the value is sent to the client's browser as text.  This statement is used to display the value of Session("subnum") and Session("condition") to the client.  This normally would not be done, of course, but may be useful to double-check that things are working correctly.  Also, such statements have been used to give participants a "verification number" at the end of the experiment so that they are able to prove that they completed the experiment.

    Second, the more frequently-used ASP statement is an IF...THEN...ELSE statement in combination with a Session variable.  The general structure of such commands is, "IF the value of the Session variable is equal to x, THEN send the first set of text to the client, ELSE send the second set of text."  In ASP code, that is:

<% IF Session("variablename") = value THEN %>
Text 1
<% ELSE %>
Text 2
<% END IF %>

Therefore, when the randomly assigned value for the Session variable equals the value specified, the text below the line containing the IF...THEN statement will be sent to the client's browser---and only that text.  If the randomly assigned value for the Session variable does not equal the value specified, then the text below the ELSE statement will be sent to the browser.  NOTE: for each IF statement there must be an END IF statement at the end of the final set of text.

    Of course, for most studies a range of conditions will receive the same set of text within each manipulation.  Thus, the ASP code in the example above used statement that specify that range using statements that the value of Session("condition") is greater than or equal to (>=) one value AND less than or equal to (<=) another value.  To specify two ranges of values, as for manipulation #2 in the above example, the two ranges are combined with an OR statement.

    To easily select a range of conditions that constitute columns in tables like that at the top of this page, it is best to use the logical command Mod, standing for modulus.  This statement returns the value of the remainder of the quotient for the two values. For example, 8 Mod 5 would return a value of 3, which is the remainder of 8 divided by 5.  In the example above, the IF statement for the third manipulation grabs the first two columns, whose condition numbers when divided by 4 equal either 1 or 2.  The IF statement for the fourth manipulation grabs all the even-numbered conditions, whose condition numbers when divided by 2 equal zero.

    Greater-than-two-level variables.  Some variables that you may have will have more that two levels.  In such cases, the ASP code uses an IF...THEN...ELSEIF...ELSE statement.  This statement successively checks IF the Session variable equals a value, like this for a 3-level variable:

<% IF Session("variablename") = value THEN %>
Text 1
<% ELSEIF Session("variablename") = value THEN %>
Text 2
<% ELSE %>
Text 3
<% END IF %>

An unlimited number of ELSEIF statements can be used. Thus the only difference when greater-than-two-level variables are involved is the addition of the ELSEIF statements for each set of additional manipulated text.

    Finally, to save yourself from typing in "Session("condition") over and over again, you could add the statement <% cond = Session("condition") %> to the page, and then use the variable 'cond' in later statements, so that your manipulations look like this:

<% cond = Session("condition") %>
<% IF cond = value THEN %>

Text 1
<% ELSE %>
Text 2
<% END IF %>

Note: you would only need to add the statement <% cond = Session("condition") %> once to each page where you would use 'cond' for the manipulations.

    Therefore, to construct a Web page where text is manipulated (pictures/images can be manipulated too), all of the text needed--for all conditions--should be written or copied into a Web page, and then the ASP code using IF...THEN statements and Session variables can be written around the manipulated text.  Of course, the ASP code should be written in as HTML code, not text.  So that this page can work properly, it must be saved with an ".asp" extension.

 

 

Guide for Running Studies over the Web with ASP

    The tutorial begins with a demonstration how Active Server Pages (ASP) code is used to manipulate the content within an individual Web page.  Arguably two of the most important elements necessary for an experimental study over the Web are random assignment of conditions and the ability to present the remote participant-client with the correct stimulus materials corresponding to the condition to which he or she has been randomly assigned.  This page describes important elements of how ASP accomplish these tasks.

    The table below represents a 2-by-2-by-2-by-2 factorial between-subjects design.  The variables manipulated are the age (18 or 40) and sex of the defendant, whether he was seen in the area of the crime or had an alibi, and whether he knew the victim or not.  Below the table is printed a random subject number between 1 and 9,999,999, a random condition number between 1 and 16, and the corresponding text for each of the manipulations for that condition.

    Hit "Reload" (or "Refresh") on your browser.  The numbers should change, as should the text to correspond with the new condition number.


  Seen Alibi
Argue No Know Argue No Know
18 Y.O. Male 1 2 3 4
Female 5 6 7 8
40 Y.O. Male 9 10 11 12
Female 13 14 15 16

 

Your subject number is: 9121449

Condition number: 5

Manipulation 1: The defendant, Joe Smith, was 18 years old at the time of the crime.

Manipulation 2: The defendant is a female .

Manipulation 3: The defendant was seen in the area 10 minutes after the crime.

Manipulation 4: The defendant was seen arguing with the victim, Frank Jones, the day before in a bar.


    How this is accomplished can be seen in the box below, which gives the HTML code for the present page (up to this point).  The ASP code is displayed between the <% and %> tags, and appears in red, at least in FrontPage.  It is processed on the server before the HTML code (in blue and black) is sent to the client. 

<html>
<
body
>

<%
Randomize
u = Round(Rnd*9999999)
Session("subnum") = u
Randomize
c = Round((Rnd*16 + 0.5))
Session("condition") = c
%>

<p>Your subject number is: <%= Session("subnum") %></p>
<p>
Condition number: <%= Session("condition") %></p>
<p>
Manipulation 1: The defendant, Joe Smith, was
<% IF Session("condition") <= 8 THEN %>
18
<% ELSE %>
40
<% End if %>
years old at the time of the crime.</p>
<p>
Manipulation 2: The defendant is a
<% IF (Session("condition") >= 1 AND Session("condition") <= 4) OR (Session("condition") >= 9 AND Session("condition") <= 12) THEN %>
male
<% ELSE %>
female
<% End if %>
.</p>
<p>
Manipulation 3:
<% IF (Session("condition") Mod 4 = 1) OR (Session("condition") Mod 4 = 2) THEN %>
The defendant was seen in the area 10 minutes after the stabbing.
<% ELSE %>
The defendant has an alibi for the time of the murder.
<% End if %>
</p>
<p>
Manipulation 4:
<% IF Session("condition") Mod 2 = 0 THEN %>
The defendant did not know the victim Frank Jones.
<% ELSE %>
The defendant was seen arguing with the victim, Frank Jones, the day before in a bar.
<% End if %></p>

</body>
</html>

   The key to manipulating content within a page is the Session variable.  Arguably the most valuable tool of the server-side scripting of Active Server Pages is the Session variable.  Each participant that is connected to the server at any given time has a single, unique Session object.  This Session object can store an unlimited number of Session variables that will apply exclusively to one participant.  Most important, the value of the variable is stored on the server, and thus even if the content of the pages is changing the Session variable remains unaltered until either a script changes its value or it expires.  Session variables are defined within ASP code by the command Session("variablename") = value. The value may be either a text string or a numerical value. 

    In the box above, the Session variables called Session("subnum") and Session("condition") are used.  The first section of ASP code assigns a random number between 1 and 9,999,999 to Session("subnum"). The Rnd command in VBScript chooses a random number between 0 and 1; this is multiplied by 9,999,999, and then that result is rounded to the nearest integer with the Round command.  Similarly, a random condition number between 1 and 16 is assigned to Session("condition").  Now, additional code is needed to send the correct HTML code to the client's browser according to the assigned condition number.

    First, the current value of a Session variable can be displayed to the client using the statement: <%= Session("variablename") %>.  This is the same as writing: <% response.write Session("variablename") %>.  Both statement place the value of the Session variable in the place of the statement, and then the value is sent to the client's browser as text.  This statement is used to display the value of Session("subnum") and Session("condition") to the client.  This normally would not be done, of course, but may be useful to double-check that things are working correctly.  Also, such statements have been used to give participants a "verification number" at the end of the experiment so that they are able to prove that they completed the experiment.

    Second, the more frequently-used ASP statement is an IF...THEN...ELSE statement in combination with a Session variable.  The general structure of such commands is, "IF the value of the Session variable is equal to x, THEN send the first set of text to the client, ELSE send the second set of text."  In ASP code, that is:

<% IF Session("variablename") = value THEN %>
Text 1
<% ELSE %>
Text 2
<% END IF %>

Therefore, when the randomly assigned value for the Session variable equals the value specified, the text below the line containing the IF...THEN statement will be sent to the client's browser---and only that text.  If the randomly assigned value for the Session variable does not equal the value specified, then the text below the ELSE statement will be sent to the browser.  NOTE: for each IF statement there must be an END IF statement at the end of the final set of text.

    Of course, for most studies a range of conditions will receive the same set of text within each manipulation.  Thus, the ASP code in the example above used statement that specify that range using statements that the value of Session("condition") is greater than or equal to (>=) one value AND less than or equal to (<=) another value.  To specify two ranges of values, as for manipulation #2 in the above example, the two ranges are combined with an OR statement.

    To easily select a range of conditions that constitute columns in tables like that at the top of this page, it is best to use the logical command Mod, standing for modulus.  This statement returns the value of the remainder of the quotient for the two values. For example, 8 Mod 5 would return a value of 3, which is the remainder of 8 divided by 5.  In the example above, the IF statement for the third manipulation grabs the first two columns, whose condition numbers when divided by 4 equal either 1 or 2.  The IF statement for the fourth manipulation grabs all the even-numbered conditions, whose condition numbers when divided by 2 equal zero.

    Greater-than-two-level variables.  Some variables that you may have will have more that two levels.  In such cases, the ASP code uses an IF...THEN...ELSEIF...ELSE statement.  This statement successively checks IF the Session variable equals a value, like this for a 3-level variable:

<% IF Session("variablename") = value THEN %>
Text 1
<% ELSEIF Session("variablename") = value THEN %>
Text 2
<% ELSE %>
Text 3
<% END IF %>

An unlimited number of ELSEIF statements can be used. Thus the only difference when greater-than-two-level variables are involved is the addition of the ELSEIF statements for each set of additional manipulated text.

    Finally, to save yourself from typing in "Session("condition") over and over again, you could add the statement <% cond = Session("condition") %> to the page, and then use the variable 'cond' in later statements, so that your manipulations look like this:

<% cond = Session("condition") %>
<% IF cond = value THEN %>

Text 1
<% ELSE %>
Text 2
<% END IF %>

Note: you would only need to add the statement <% cond = Session("condition") %> once to each page where you would use 'cond' for the manipulations.

    Therefore, to construct a Web page where text is manipulated (pictures/images can be manipulated too), all of the text needed--for all conditions--should be written or copied into a Web page, and then the ASP code using IF...THEN statements and Session variables can be written around the manipulated text.  Of course, the ASP code should be written in as HTML code, not text.  So that this page can work properly, it must be saved with an ".asp" extension.

 

 


IF YOU WISH TO RETURN THE HOME PAGE, CLICK HERE

IF YOU HAVE COMMENTS OR QUESTIONS, EMAIL ME AND LET ME KNOW