Client-side scripting languages, such as JavaScript and Jscript, can be programmed to provide user interface elements that are not possible in traditional HTML. In general, client side scripting makes dynamic behavior possible without accessing the web server.
For instance, events such as mouse-overs (when the cursor is moved over an object) can be detected and used to create useful feedback for users. Mouse-over events can be used to trigger a visual cue to the user by changing a graphic to indicate that an object is clickable.
This effect is called a rollover. Rollovers can also be used to provide contextual help by presenting messages that explain what will happen if the user clicks on the object.
Another good use for scripts is validating user-supplied data in forms prior to sending the data to the server.
This allows common user errors to be detected and responded to without the latency associated with a server request. Scripts can be used to program other sophisticated behaviors such as interactive forms that update calculations when information is changed.
Despite these positive aspects, scripting also tends to be overused, complicating the interface and slowing user interaction with bloated script code and gratuitous graphics. Rollovers, for example, when used to hid the full description of a link whose title is insufficiently descriptive, force the user to engage in minesweeping (moving the mouse to discover hidden information) in order to do a task.
To implement successful client-side scripts, code defensively. Be thorough and cautiously rule out possible errors in order to produce robust code. Put all script subroutines in the head portion of the HTML page.
This prevents the user from calling routines that have not been defined. Wrap these routines in comment tags so that older browsers will ignore them. Specify which script and version you’re using if you are using routines that are not backward-compatible with older browsers. Know which routines are not cross-platform-compatible and find other solutions.
In addition, follow good software engineering practices. Scripting languages are very similar to general-purpose programming languages and can be just as difficult to debug. Factor the scripts into small, cohesive subroutines that perform one function only. Such routines are easier to write, test, and debug.
For complex scripts, consider creating flowcharts or structure charts to prevent logic errors. Declare all variables and document their purposes and types. Document each subroutine similarly. Keep page-specific variables and constants at the top of the code so you don’t have to wade through all the code to customize it for every page.
No Comments so far ↓
There are no comments yet...Kick things off by filling out the form below.