Chapter 3 DynaScript Predefined Objects


document properties

The document object has these properties:

cachedOutputTimeOut property

Syntax

document.cachedOutputTimeOut

Description

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.

Example

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;
-->

connectionId property

Syntax

document.connectionId

Description

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.

Example

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

See also

"connection object".

connectionName property

Syntax

document.connectionName

Description

Name of the associated connection object (string).

Example

This example displays the connection name of a script's associated connection object.

<!--SCRIPT 
/* display the connection name */
document.WriteLn( document.connectionName );
-->

See also

"connection object".

contentType property

Syntax

document.contentType

Description

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.

Example

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") );
-->

description property

Syntax

document.description

Description

Description associated with the document (string).

Example

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 );
-->

id property

Syntax

document.id 

Attributes

This property is read-only.

Description

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.

Example

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

lastModified property

Syntax

document.lastModified 

Attributes

This property is read-only.

Description

Returns the time (string) of the last change to the document (for example, 1996-10-24 14:24:29 ).

Example

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

location property

Syntax

document.location

Description

Full URL for the document.

Note  

Linked Folders
You cannot move a linked folder inside a linked folder.

Example

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

name property

Syntax

document.name

Description

Name (including extension, if any).

Example

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

parent property

Syntax

document.parent

Description

The containing folder object of this document (document).

Note  

Linked Folders
You cannot move a linked folder inside a linked folder.

Example

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
-->

redirect property

Syntax

document.redirect

Description

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.

Example

This example directs a request to http://www.sybase.com:

<!--SCRIPT 
document.redirect = "http://www.sybase.com";
-->

size property

Syntax

document.size 

Attributes

This property is read-only.

Description

Length in bytes (integer) of the document.

Example

This example displays the size of the document:

<!--SCRIPT 
/* Size of the document. */
document.WriteLn( document.size );
-->

source property

Syntax

document.source

Description

Uninterpreted document content (source).

Example

This example changes the contents of /site/sample.stm to "hello world":

<!--SCRIPT 
sampleDoc = site.GetDocument( "/site/sample.stm" );
sampleDoc.source = "hello world";
-->

status property

Syntax

document.status

Description

A string that indicates a status code and a brief explanation of that code. The status code values are defined in the HTTP specification.

Example

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>" );
}
-->

type property

Syntax

document.type 

Attributes

This property is read-only.

Description

The type of Dynamo document (string). One of:

Example

This example displays the document type:

 <!--SCRIPT 
/* type of document */
document.WriteLn( document.type );
-->

value property

Syntax

document.value.variable 

Attributes

This property is read-only.

Description

Values of passed-in arguments (URL arguments, typically from an HTML form), where variable is the argument name (array).

Example

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.