Southend Linux User Group

DHTML

Dynamic HTML – Scripting languages

New technologies and Web browsers are encouraging the creation of more active Web pages by adding program code to the static HTML page. This is known as client side scripting, because the code runs on the users machine. Because JavaScript (or VBScript ) resides in the Web page, it doesn’t require server processing time, or incur the overhead of a communications link, so it runs faster ;

Forms allow the Web page to get input from a user, such as a topic to be searched for, in a keyword search for example. Once the form is complete it can be submitted (sent) to the server for processing. Client side scripting can be used to validate is input prior to sending it to the server.

What is Scripting – When to Use It

Scripting enables you to set and store variables and to work with data in your HTML code. Many Web sites now employ scripting to check which browser a user is running, validate input, work with applets or controls, and communicate to the user.

Two of the most popular scripting languages today are ECMAScript (a standardized scripting language based on JavaScript), which Microsoft have implemented as JScript and VBScript. You can use any scripting language you like as long as your users browsers support it. In fact, you can use a combination of scripting languages in your HTML source code.

JavaScript in an HTML page

JavaScript is the default scripting language for developing active Web page content. It can be used to programmatically change the properties within tags. The code is activated by some event, such as the user pressing a button, or moving the mouse over an image. The following "Hello World!" example compares JavaScript and VBScript.

<HTML> <head>
<!-- This script runs in response to the user -->
<!-- clicking the button -->
<SCRIPT LANGUAGE="JavaScript" FOR="Btn1" EVENT="OnClick" >
    alert("Hello from JavaScript");
</SCRIPT>
</HEAD>
<BODY>
  <H3>Running a simple JavaScript</H3><HR>
  <FORM>
    <INPUT id="Btn1" TYPE="BUTTON" VALUE="Click Me">
  </FORM>
</BODY>
</HTML>

When a browser reads this page, it finds the <SCRIPT> tags, recognizes that there is a piece of JavaScript (or VBScript code) and saves it. When you click the button, an OnClick event is generated by Btn1, defined by the id property within the <INPUT> tag. The browser makes the connection between the Btn1 event and the script and calls JavaScript Alert (or VBScript MsgBox) to display the enclosed message.

Instead of running the code on the clients machine it may be run instead on the server using PHP or in Microsofts proprietary environment Active Server Pages (ASP).
Running the code onthe server is known as server side scripting. In this case the server scans the requested web page and runs any script it finds before the page is sent to the browser. After the script is run the resulting web page is then sent to the user. A typical example would be to filter just those records from a database the user has requested.

VBScript in an HTML Page

Microsoft Explorer is the only browser which understands VBScript so do not use it. The de facto standard for client side scripting is Javascript

Below is the corresponding example written using VBScript to  illustrate how a piece of VBScript is embedded in the body of an HTML page.

<HTML>
<head>
<!-- This script runs in response to the user -->
<!-- clicking the button -->
<SCRIPT LANGUAGE="VBScript" FOR="Btn1" EVENT="OnClick">
    MsgBox "Hello from VBScript"
</SCRIPT>
</HEAD>
<BODY>
  <H3>Running a simple VBScript</H3><HR>
  <FORM>
     <INPUT NAME="Btn1" TYPE="BUTTON" VALUE="Click Me">
  </FORM>
</BODY>
</HTML>

Here, because the <SCRIPT> tag specifies the event and the name of the button control, the Sub and End Sub statements normally found in VBScript code are not needed. 

Author: Alan Campion - Page reference: 2792
Last modified: Alan Campion - 2015-02-15