The HTML editor includes features that help you create scripts. You can create event handlers for elements on the page, which are scripts that run in response to actions such as when a user chooses a button, when a document first loads, or another event. You can also use editor features to create standalone script blocks to contain any script, not only event handlers.
Tip If you insert script into the body portion of a document, choose Show Details in the Design toolbar. This displays a glyph for the script when you are in Design view. Without the glyph, the script does not appear in Design view, and you might delete it accidentally.
To create event-handling scripts, you use the Script Outline window. The Script Outline window shows you all scriptable elements in your page, and for each element, the events you can write handlers for. The Script Outline window divides the elements and scripts into those that will run on the client and those that will run on the server.
In the editor, you write scripts in Source view. However, if you are working in Design view, you can start scripting for an element you are working with.
To start scripting from Design view
The editor switches to Source view. It also displays the Script Outline window and places the focus on the default handler for that element. If the element you clicked does not have an ID attribute, the HTML editor adds one.
With the Script Outline window displayed, you can create a skeleton event handler for any element on the page.
To create an event handler
When you double click the event name, the editor performs the following actions:
onclick=
) to the element.The language used for an event handler skeleton depends on the default language for client or server script, as set in the Property Pages dialog box for the current document. For VBScript functions, the format is:
Sub elementID_event
End Sub
For JavaScript functions, the format is:
function elementID_event(){
}
When creating JavaScript event handlers, the editor also adds the following attributes to the HTML element itself:
event="return elementID_event()"
In addition to creating event handlers, you can create standalone script blocks. This is useful if you want to create procedures (subroutines or functions) called by other scripts, or if you want to create global script that runs as soon as the page is processed by the browser.
To create a standalone script block
The HTML editor creates a <SCRIPT> block. If you choose Server, the script tag contains the attribute RUNAT=SERVER. The script block's LANGUAGE attribute is set to the default language for the client or server.