ONE Active Server Pages Product Home Page Developer Site Version


Adding Scripts

Once you have created an ASP page, as described in Creating an ASP Page, you can use a text editor or other authoring tool to insert script commands into the page. ASP pages can include both client-side scripts, which are processed by the browser, and server-side scripts (or ASP scripts), which are processed by the ASP Server.

ASP scripts enable you to dynamically create HTML responses based on the user's identity, parameters in the HTTP request, and interactions with other objects, such as ASP built-in objects, components, and databases. ASP enables you to assign values to variables, request information from the server, or combine any set of commands into procedures.

For example, a common use of Web applications is to process a form submitted by a browser. With ASP, you can embed scripts directly into an HTML file to process the form. The ASP Server processes the HTML and script commands and returns the results to the browser.

Within the ASP page, script blocks are set off from other text by using delimiters. You must use different script delimiters to distinguish between client-side and server-side scripts. You enclose client-side scripts between the <script> and </script> tags. You enclose server-side scripts between the delimiters <% and %>.

You can write ASP scripts in either VBScript or JScript. The default scripting language for Sun ONE ASP is VBScript, but you can specify the scripting language for each ASP page. Your system administrator can also change the default scripting language for the ASP Server. For more information, see Changing the Scripting Language.

As the ASP Server processes each ASP script block, it creates HTML text that is returned to the Web server for rendering. Unlike with client-side scripts, with server-side ASP scripts you do not need to worry about the capabilities of the browser; all processing is done at the server and only standard HTML is returned.

Users cannot copy server-side scripts because only the output is returned to the browser. Consequently, to view the results of a script you have added to an ASP page, you must first publish the page to an ASP Server and then request the page by using a Web browser.

The following example shows how you can combine standard HTML tags with a simple script that provides the current time of day:

<META NAME="GENERATOR" Content="Adobe GoLive">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
 The time is now <%Response.Write Now%>

Both VBScript and JScript support the If-Then-Else construct, enabling you to embed some real logic into your HTML. The following example shows how you can set the greeting shown based upon the time of day:

<%If Time >= #12:00:00 AM# And Time < #12:00:00 PM# Then%> 
Good Morning!
<%End If%> 

See also:

Creating the Basic ASP Application

Creating an ASP Page

Using Server-side Includes

Using @Directives