Specifications

135
CHAPTER 13
Behaviors
Behaviors let users make their HTML pages interactive. They offer web designers an easy way to
assign actions to page elements by filling in an HTML form.
You should write behavior actions when you want to share functions with users or when you want
to insert the same JavaScript function repeatedly but change the parameters each time.
Note: You cannot use behaviors to insert VBScript functions directly; however, you can add a VBScript function
indirectly by editing the DOM in the applyBehavior() function.
The term behavior refers to the combination of an event (such as onClick, onLoad, or onSubmit)
and an action (such as Check Plugin, Go to URL, Swap Image). The browser determines which
HTML elements accept which events. Files that list events that each browser supports are stored
in the Configuration/Behaviors/Events folder within the Dreamweaver application folder.
Actions are the part of a behavior that you can control; so when you write a behavior, youre really
writing an Action file. Actions are HTML files. The
BODY of an Action file generally contains an
HTML form that accepts parameters for the action (for example, parameters that indicate which
layers are to be shown or hidden). The
HEAD of an Action file contains JavaScript functions that
process form input from the
BODY and control the functions, arguments, and event handlers that
are inserted into a users document.
Note: For information about server behaviors that provide web application functionality, see “Server Behaviors” on
page 145.
How Behaviors work
When a user selects an HTML element in a Dreamweaver document and clicks the plus (+)
button, the following events occur:
1 Dreamweaver calls the canAcceptBehavior() function in each Action file to see whether this
action is appropriate for the document or the selected element.
If the return value of this function is
false, Dreamweaver dims the action in the Actions pop-
up menu. (For example, the Control Shockwave action is dimmed when the users document
has no Shockwave movies.) If the return value is a list of events, Dreamweaver compares each
event with the valid events for the currently selected HTML element and target browser until
it finds a match. Dreamweaver populates the Events pop-up menu with the matched event
from
canAcceptBehavior() at the top of the list; if no match exists, the default event for the
HTML element (marked in the Event file with an asterisk [*]) becomes the top item. The
remaining events in the menu are assembled from the Event file.
2 The user selects an action from the Actions pop-up menu.