Visual InterDev
Web pages are filled with information for users, but most of it is static. You can use scripts to display dynamic information to the user.
Displaying Information from Client Scripts
Because client scripts run on the browser, they give you flexibility in how you want to display information to the user. One way is to display message boxes, the way stand-alone applications on a computer often do.
To display message boxes from client scripts
In the client script, call the window object's alert method:
<SCRIPT LANGUAGE="VBScript"> window.alert("Hello, World.") </SCRIPT>
To reference the current window, you can omit the reference to the window object.
If you are writing in VBScript, you can use the MsgBox function, which allows you to specify particular buttons. For details, see the .
You can also display information from client scripts directly on the page, intermingled with the HTML text.
To display information in the page from client scripts
Call the document.write method, which puts text at the location in the page where the script is executing. For example:
<SCRIPT LANGUAGE="VBScript"> document.write "The current time is " & time </SCRIPT>
If your page contains an HTML text box or text area control, you can change the contents of the box to display information.
To display information inside an HTML control
Set the value property of the text box or text area control, as in the following example:
<SCRIPT LANGUAGE="VBScript"> Function btnShowTime_onclick() document.Form1.txtTime.value = time End Function </SCRIPT>
If your application will be running in browsers that support Dynamic HTML (such as Microsoft® Internet Explorer 4.0), you can directly set the text of any tag that has a name or ID.
To set the text of a tag using DHTML
Set the tag's innertext property. The tag must have an ID or a name that you can reference in the script. The following page illustrates a tag and how to set it.
<HEAD> <SCRIPT LANGUAGE="VBScript"> Function btnChangeText_onclick() para1.innerText = "The new time is: " & time End Function </SCRIPT> </HEAD> <BODY> <P ID=para1>This text will be replaced.</P> <P><INPUT TYPE="button" NAME="btnChangeText" VALUE="Change text"></P> </BODY>
To format the text you are displaying, you can include HTML tags, as in the following example:
<SCRIPT LANGUAGE="VBScript">
document.write "<P>The current time is <B>" & time & "</B></P>"
document.write "<P>The current date is <B>" & date & "</B></P>"
</SCRIPT>
If the information you want to display includes characters that are reserved in HTML — such as < and > — you cannot directly include them in the string to display.
To display reserved characters
Use the HTML syntax for ASCII characters, such as
<
or<
for the opening angle bracket (<):<SCRIPT LANGUAGE="VBSCRIPT"> document.write "<Click here>" </SCRIPT>
Displaying Information from Server Scripts
To display information to a user from a server script, you usually make it part of the page that is sent to the browser.
To display information on a page from a server script
Call the Response.Write method, passing it the information you want to display:
<% Response.Write "The current time on the server is " & Time %>
–or–
Use the "=" operator, which is a shorter version of the same method:
<% = "The current time on the server is " & Time %>
–or–
If the information is not in a variable or calculated in an expression, make it part of the page. To display text, make sure it is outside the <% %> delimiters and is not part of a
<SCRIPT RUNAT="SERVER">
block. You can easily include HTML tags this way, as in the following example:<BODY> <H1>The Time Page</H1> <% t = time %> <P> The current time at the server is <B><%=t%></B> </P> </BODY>
The server cannot directly display a message box, but a server script can create a client script that displays one.
To display a message box in a server script
Create a client script, and then enclose it in server script that shows it conditionally. In the following example, the script block is sent to the browser only if the error flag on the server is true.
<%if fError = True then%> <SCRIPT Language="VBSCRIPT"> alert("An error occured on server.") </SCRIPT> <%End If%>
If the information you want to display includes characters that are reserved in HTML — such as < and > — you cannot include them in the string to display.
To display reserved characters
Call the HTMLEncode method to convert the characters to HTML syntax for ASCII characters:
<%= Server.HTMLEncode("The paragraph tag: <P>") %>