INLS161-001 Fall 2021

Tools for Information Literacy

Client side scripting

What is the difference between server- and client-side scripting?

client-side scripting requires browsers to run the scripts on the client machine
and does not interact with the server while processing the client-side scripts.
Client side scripts do not need a server to work.
They are not for collecting data,
rather they are for introducing some sort of dynamism into your web page.

As it implies, client side scripts are scripts on a page that do all their work on the client side of the relationship. They do not depend on the server. As such, there are things they cannot do (they are not good at collecting data and storing it, for example). But there are things they can do and do well, such as causing the page to react to user input.

CGI scripts are one server-side variant. Now we will be looking at client-side scripts. Client-side scripts are very often written in JavaScript, since JavaScript is a scripting language supported by most browsers.

According to W3Schools,

Client-side scripting is about "programming" the behavior of the browser.
what is it? DHTML Javascript adding to page examples other events

back to top

Dynamic HTML & JavaScripts

What do we mean by "dynamic" HTML? According to one definition,

Dynamic HTML is a collective term for a combination of HTML tags and options, that will let you create Web pages more animated and more responsive to user interaction than static HTML.

DHTML, then, is expressed in scripts written in your HTML code to create programs that add interactivity to your page. You can find tutorials for both all over the web as well as sites that offer free examples of DHTML scripts. An example is Dynamic Drive.

JavaScript is a client-side scripting language that adds interactivity to web pages and lets designers control various aspects of the browser itself.

A scripting language like JavaScript is somewhere between a markup language, like HTML, and a full-blown programming language, like Java.

With it, you can add extra functionality to your web site by using short segments of scripting code that has a syntax that is fairly easy to understand.

As with CGI scripts, there are numerous site on the web that offer free JavaScript scripts for use, many that offer to sell such scripts, and innumerable ones that incorporate JavaScript in their code. You can look at the underlying code of any page to see what they are doing.

what is it? DHTML Javascript adding to page examples other events

back to top

JavaScript background

JavaScript is a client-side scripting language. A web page designer creates simple script programs that are embedded in HTML documents and are interpretable by "script-aware" browsers.

JavaScript is well suited for responding to user actions and for doing simple processing without getting servers involved.

JavaScript is not well-suited for applications that require large amounts of data or that need access to files on the browser's machine.

Tightly intertwined with JavaScript is the Document Object Model (or DOM).

Much of JavaScript revolves around the notion of an event and what things can happen when an event occurs.

So a script allows you to specify what actions you'd like to happen when the user does something (like click on a button in a form, mouse over an object, or something else).

what is it? DHTML Javascript adding to page examples other events

back to top

How do you add JavaScript to a page?

Understanding HTML is handy, because scripts are HTML commands, entered into the HTML code. You need to tell the browser that you are using a script and what kind of script you are using.

what is it? DHTML Javascript adding to page examples other events

back to top


The script explained:

Remember ...
UNIX/LINUX ⇒ command argument value
HTML ⇒ tag attribute value

The following script is an automatic script: it automatically adds text to a page

script - identifies that a script is being used
type - identifies the scripting language in use
="text/javascript" - which, in this case, is JavaScript
document.write("...") - content of the script
/script - closes the script section

<title>Simple Scripts</title>
<script type="text/javascript" >
document.write("<h2>Table of Factorials</h2>");
for(i = 1, fact = 1; i < 10; i++, fact *= i) {
document.write(i + "! = " + fact);

<p>Other text in the page.</p>

The following script is a triggering script: it requires a user action to trigger it

In this case, it needs an HTML tag that the intrinsic event depends upon; it needs

  1. a trigger,
  2. an event that the trigger causes to happen, and
  3. a script that runs when the event occurs.

The event name and the script go inside the HTML tag and the script is enclosed in double quotation marks.

<title>Triggering Scripts</title>
<h2>What time is it?</h2>
<button type="button" onclick="document.getElementById('demo').innerHTML = Date()">Click me to display Date and Time.</button>
<p id="demo"></p>

more variations on the same theme

what is it? DHTML Javascript adding to page examples other events

back to top

Other events

Try some of them out by replacing the event in the code above.

If the script requires quotation marks, "use 'single quotes' to differentiate from the double quotes that enclose the entire script."

Examples from JavaScript: The Definitive Guide

what is it? DHTML Javascript adding to page examples other events

back to top

Copyright © R.E. Bergquist 2014- | Last Updated on | Powered by w3.css