Chapter 3 DynaScript Predefined Objects
The document
object
has these properties:
document.cachedOutputTimeOut
Duration of time (integer) for which the generated output of a script or template is cached. The default is zero. This property is not persistent-It is reset to zero if you restart the Web server.
This example sets the cache time of the current document output to be 3 minutes.
<!--SCRIPT
/* setting the cache time */
document.WriteLn( "This is my output that will be cached for 3 minutes." );
document.cachedOutputTimeOut = 3;
-->
document.connectionId
ID of associated connection object (integer). Connection IDs may change it you restart the Web server. For this reason, Sybase recommends that you use the connectionName property instead.
This example displays the connection Id of a script's associated connection object:
<!--SCRIPT
/* displays the connection Id */
document.WriteLn( document.connectionId );
-->
The output from this example might look like this:
0
document.connectionName
Name of the associated connection object (string).
This example displays the connection name of a script's associated connection object.
<!--SCRIPT
/* display the connection name */
document.WriteLn( document.connectionName );
-->
document.contentType
Type of document being displayed (string). The content types are standard MIME content types. This property is not persistent and will be reset if the Web server is restarted.
This example selects a graphic called bart.gif from a table in the database and then displays it to a browser. The second part of the example tells the browser to expect an image rather than HTML.
<!--SQL
select data from imagetable where imagename = 'bart.gif'
-->
<!--SCRIPT
/* set the content type to image */
document.contentType = "image/gif";
document.write( SQL.GetValue("data") );
-->
document.description
Description associated with the document (string).
This example displays the description that was entered when the document /Site/descript.ssc was created.
<!--SCRIPT
descDoc = site.GetDocument ( "/Site/descript.ssc" );
document.WriteLn( descDoc.description );
-->
document.id
This property is read-only.
Internal document object ID (integer). IDs may change if you restart the Web server. For this reason, Sybase recommends the use of the documentName property to identify documents instead of the id property.
This example displays the document ID.
<HTML>
<TITLE>docid.stm</TITLE>
<BODY>
<H1>Display the document's Id number.</H1>
<p>The document id for docid.stm is: </p>
<!--SCRIPT
document.WriteLn( document.id );
-->
</BODY>
</HTML>
The output would be similar to:
Display the document's Id number.
The document id for docid.stm is:
265
document.lastModified
This property is read-only.
Returns the time (string) of the last change
to the document (for example, 1996-10-24 14:24:29
).
This example displays the date the document was last altered:
<!--SCRIPT
document.WriteLn( document.lastModified );
-->
The output from this example is:
1997-06-06 10:40:30
document.location
Full URL for the document.
Linked Folders
You cannot move a linked folder inside
a linked folder.
This example displays the location of the document object.
<!--SCRIPT
/* location of the document. */
document.WriteLn( document.location );
-->
The output from this example is:
/Site/location.ssc
document.name
Name (including extension, if any).
This example displays the name of the document.
<!--SCRIPT
/* name of the document. */
document.WriteLn( document.name );
-->
The output from this example is:
name.ssc
document.parent
The containing folder object of this document (document).
Linked Folders
You cannot move a linked folder inside
a linked folder.
This example moves the document /site/sample/products.stm into /site/myFolder:
<!--SCRIPT
myFolderDoc = site.GetDocument( "/site/myFolder" );
productsDoc = site.GetDocument( "/site/sample/products.stm" );
productsDoc.parent = myFolderDoc
-->
document.redirect
The name of the URL to which the current request is to be directed (string). This property is not persistent and will be reset if you restart the Web server.
This example directs a request to http://www.sybase.com:
<!--SCRIPT
document.redirect = "http://www.sybase.com";
-->
document.size
This property is read-only.
Length in bytes (integer) of the document.
This example displays the size of the document:
<!--SCRIPT
/* Size of the document. */
document.WriteLn( document.size );
-->
document.source
Uninterpreted document content (source).
This example changes the contents of /site/sample.stm to "hello world":
<!--SCRIPT
sampleDoc = site.GetDocument( "/site/sample.stm" );
sampleDoc.source = "hello world";
-->
document.status
A string that indicates a status code and a brief explanation of that code. The status code values are defined in the HTTP specification.
This example prompts the user for a user ID and a password, then displays the status code.
<!--SCRIPT
authType = document.GetServerVariable( "AUTH_TYPE" );
if( authType != null ) {
authType = authType.toUpperCase();
}
if( authType == "BASIC" ) {
// Web server has successfully authenticated
// the user
document.writeln( "<HTML>Welcome</HTML>" )
} else {
// document.status is part of the HTTP
// header sent to the browser.
// For "401" a browser will prompt the
// user for a userid and password and attempt
// to login to the Web server
document.status = "401 Unauthorized";
// since the HTTP headers are only seen by the
// browser, we still need to provide an
// informational message which
// will be displayed if the user selects
// cancel in the login dialog
document.writeln( "<html><body><h1>" );
document.writeln( document.status );
document.writeln( "</h1></body></html>" );
}
-->
document.type
This property is read-only.
The type of Dynamo document (string). One of:
directory
Dynamo
folder
directoryLink
Dynamo
linked folder
image
binary
file
script
DynaScript
file
text
Dynamo
HTML template
This example displays the document type:
<!--SCRIPT
/* type of document */
document.WriteLn( document.type );
-->
document.value.variable
This property is read-only.
Values of passed-in arguments (URL arguments, typically from an HTML form), where variable is the argument name (array).
This example converts a user provided temperature from Celsius to Fahrenheit or from Fahrenheit to Celsius.
The first part of the example prompts the user
to select the type of conversion and to enter a value. The values
are held in the parameters theType
and temperature
:
<HTML>
<H1>Converting Temperatures </H1>
<BODY>
<P>This page allows you to convert a temperature from <I>Celsius</I> to
<I>Fahrenheit</I> or from <I>Fahrenheit</I> to <I>Celsius</I>.
<BR>
<HR WIDTH="100%">
<P>Select the appropriate button and enter the temperature you would like
to convert.
<FORM METHOD=POST ACTION="convert.stm">
<OL>
<LI><INPUT TYPE="radio" NAME="theType" value="CtoF" CHECKED>Celsius to Fahrenheit<BR>
<INPUT TYPE="radio" NAME="theType" value="FtoC">Fahrenheit to Celsius<BR>
<LI><INPUT TYPE="text" NAME="temperature" SIZE="4"> Temperature
</OL>
<P><INPUT TYPE="submit"></p>
<P><INPUT TYPE="RESET" VALUE="Clear Form"></P>
</FORM>
</BODY>
</HTML>
The next part of the example receives the values entered by the user and uses the values to calculate the requested temperature:
<HTML>
<TITLE>convert.stm</TITLE>
<BODY>
<H1>Temperature</H1>
<P>Your answer is: </P>
<!--SCRIPT
// receiving user provided data
var conversionType = document.value.theType;
var tempnumber = document.value.temperature;
var DemoObj = CreateObject( "SybaseDemoObject.TempConvert" );
if( conversionType == "CtoF" ){
var c = DemoObj.ConvertCtoF( tempnumber );
document.WriteLn( "The Celsius temperature of " + tempnumber + " is " + c + " on the Fahrenheit scale." );
} else {
var f = DemoObj.ConvertFtoC( tempnumber );
document.WriteLn( "The Fehrenheit temperature of " + tempnumber + " is " + f + " on the Celsius scale." );
}
-->
</BODY>
</HTML>
The first part of the next example prompts
the user to select items from a list in which all the items have
the same name element of "choice"
.
If only one item is selected, the value is held in document.value.variable.
If two or more items are selected from the list the values are held
in document.value[0], document.value[1],
document.value[2], and so on.
The second part of the next example displays the arguments selected from the first template.
<HTML>
<TITLE>multpar.stm</TITLE>
<BODY>
<HTML>
<H1>What Do I Have To Do Today? </H1>
<BODY>
<P> To do list:
<FORM METHOD=POST ACTION="display.stm" MULTIPLE SIZE="5">
<OL>
<INPUT TYPE="checkbox" NAME="choice" value="Laundry">Laundry<BR>
<INPUT TYPE="checkbox" NAME="choice" value="Walk the dog">Walk the dog<BR>
<INPUT TYPE="checkbox" NAME="choice" value="Wash the car">Wash the car<BR>
<INPUT TYPE="checkbox" NAME="choice" value="Groceries">Get groceries<BR>
<INPUT TYPE="checkbox" NAME="choice" value="Dust">Dust the house<BR>
</OL>
<P><INPUT TYPE="submit" VALUE="Submit List"></p>
<P><INPUT TYPE="RESET" VALUE="Clear Form"></P>
</FORM>
</BODY>
</HTML>
<HTML>
<TITLE>display.stm</TITLE>
<BODY>
<H1>My tasks are:</H1>
<!--SCRIPT
if( typeof( document.value.choice ) == "object" ) {
i = 0;
while( exists( document.value.choice[i] ) ) {
document.writeln( "value[" + i + "] = " + document.value.choice[i] );
i++;
}
} else {
document.writeln( "value = " + document.value.choice );
}
-->
</BODY>
</HTML>
The last example looks up and displays the ID for a customer whose first and last name have been sent by a browser (typically in response to an HTML form).
<!--SCRIPT
myQuery=connection.CreateQuery( "select id from customer where lname = '" + document.value.lastName + "' and fname = '" + document.value.firstName + "'" );
myQuery.MoveNext();
document.WriteLn( yQuery.GetValue(1));
myQuery.Close();
-->
Copyright © 1999 Sybase, Inc. All rights reserved. |
![]() |