Answered Essay: Research and discuss how JavaScript can be used to create dynamic web page behavior.

Research and discuss how JavaScript can be used to create dynamic web page behavior.

Find examples of web pages where it is used.

Research and discuss HTML events.

Discuss how JavaScript can be combined with HTML events to provide dynamic web page behavior.

Use your own words, please.

Expert Answer


server-side dynamic web page is a web page whose construction is controlled by an application server processing server-side scripts. In server-side scripting, parameters determine how the assembly of every new web page proceeds, including the setting up of more client-side processing.

client-side dynamic web page processes the web page using HTML scripting running in the browser as it loads. JavaScript and other scripting languages determine the way the HTML in the received page is parsed into the Document Object Model, or DOM, that represents the loaded web page. The same client-side techniques can then dynamically update or change the DOM in the same way.

A dynamic web page is then reloaded by the user or by a computer program to change some variable content. The updating information could come from the server, or from changes made to that page’s DOM. This may or may not truncate the browsing history or create a saved version to go back to, but a dynamic web page update using Ajax technologies will neither create a page to go back to, nor truncate the web browsing history forward of the displayed page. Using Ajax technologies the end user gets one dynamic page managed as a single page in the web browser while the actual web content rendered on that page can vary. The Ajax engine sits only on the browser requesting parts of its DOM, the DOM, for its client, from an application server.

DHTML is the umbrella term for technologies and methods used to create web pages that are not static web pages. Client-side-scripting, server-side scripting, or a combination of these make for the dynamic web experience in a browser.

Javascript Behaviors

This page presents a library of Dynamic HTML behaviors, modular units of Javascript code that can be associated with elements in a web page chosen with CSS selectors.

The library is based on Ben Nolan’s Behaviour.js, but with a slightly different design. The library of CSS selectors was written by Simon Willison.

I’m releasing this under the LGPL. Ben’s original library is released under a BSD license. Both of our libraries rely on Simon’s getElementsBySelector function, which doesn’t seem to be under any license.

HTML and Javascript: Don’t Cross the Streams

Dynamic HTML (DHTML) enables programmers to use Javascript to modify the style, contents, or interactive behavior of the elements of a web page. In particular, programmers can attach event handlers to document elements, which respond to user actions with programmable behavior. The easiest way to do this is to specify an event handler property directly in the HTML:

<div id="foo" onclick="alert('clicked!')">...</div>

As proponents of unobtrusive Javascript point out, there are problems with writing web pages this way. For one thing, it mingles two unrelated pieces of the web page: the document’s structure (represented by the HTML code), and its behavior (represented by the Javascript). It makes it difficult to split the task among different developers, say, a programmer and a graphic designer. And it results in a monolithic structure that’s hard to understand and maintain. Aspect-oriented programmers call this the problem of tangling.

Another problem with this code is that such web pages end up with bits of conceptually related Javascript code strewn about the web page. For example, if all div elements with the class clickable are supposed to respond to the onclick event in the same way, the programmer shouldn’t have to copy the same code in the onclick property of each such element in the web page. Aspect-oriented programmers call this problem scattering.

A Non-Solution

The alternative, of course, is to move this logic into one place in the document’s initialization code. Unfortunately, in practice this usually means writing code to select each relevant node, by searching the DOM tree or chasing child and parent pointers, and set its corresponding properties.

var nodes = document.getElementsByTagId('div');
for (var i = 0; i < nodes.length; i++) {
    if (nodes[i].className == 'clickable') {
        nodes[i].onclick = function() { alert('clicked!'); };

While this approach solves the problems of scattering and tangling, the code is bloated and hard to read. Worse, it can be brittle: the hand-written code for selecting nodes can be fragile, depending on the specific layout of the document, which tends to change often.

A Better Way

A better solution than all this searching and pointer-chasing is to use a higher-level language for selecting DOM nodes. Lucky for us the W3C has already put a lot of work into designing such a language! With CSS selectors, we can describe collections of elements in a web page according to the high-level design of the document’s structure.

For example, we can create a rule set that registers an onclick handler for all nodes of class clickable:

var myrules = {
    '.clickable' : {
        onclick : function() { alert('clicked!'); }


Now we can add, delete, and move nodes from the entire web page with the clickable class, and our event handler code remains unchanged.

If you have spent any time surfing the Web, you have no doubt encountered pages that change content and interact with you. At commercial sites, banner ads may cycle as you view the site, or may react when you place the mouse over them. Search engines such as Google and Ask Jeeves prompt you for topics and then retrieve information based on your response. These are examples of dynamic pages since their behavior changes each time they are loaded or as events occur. As this course progresses, you will learn to develop dynamic pages with similar capabilities using JavaScript. For now, you will start with simple Web pages that are able to interact with the user and display dynamic content based on that interaction.

For example, suppose you wanted to create a Web page that customized itself by asking the user their name and then incorporating that name within the text of the page. The following HTML document accomplishes this task by utilizing simple features of JavaScript, which will be explained below.


<!– Web page that displays a personalized greeting. –>


<title> Greetings </title>



<script language=”JavaScript”>

firstName = prompt(“Please enter your name”, “”);

document.write(“Hello ” + firstName + “, welcome to my Web page.”);



Whatever else you want to appear in your Web page…




JavaScript statements are commands that tell the browser to perform specific actions, such as prompting the user for their name or displaying a message within the page. The simplest way to add dynamic content to a Web page is to directly embed JavaScript statements within the HTML document using SCRIPT tags. Statements embedded between the tags <script language=”JavaScript”> and </script> are recognized by the Web browser as JavaScript code, and are automatically executed (i.e., the actions specified by the statements are carried out in order) when the page is loaded. In this example, there are two JavaScript statements within the SCRIPT tags, which combine to produce the interactive behavior described above.

  • The first JavaScript statement within the SCRIPT tags performs the task of asking the user for their name and remembering the name for future reference. firstName = prompt(“Please enter your name”, “”);This type of statement is known as an assignment statement since its purpose is to assign a name to particular value so that it can be referred to throughout the page. In this example, the value being assigned is obtained via a call to the predefined prompt function. In simple terms, a function is a collection of JavaScript statements that carry out a specific task, and a call to that function causes those statements to be executed. Here, the call to prompt causes a dialog box, a separate window where a use can enter values, to appear:

    Prompt dialog box

    The white rectangle in the dialog box is the input area where the user can enter text, then click on the OK button when input is complete. Note that the prompt message that appears within the dialog box, Please enter your name, is the text listed first inside the call to prompt. The prompt message can be any sequence of characters enclosed in quotes, which is referred to as a string in JavaScript. Note also that the call to prompt has a second string value listed, which is the default value to be initially displayed in the input box. In this case, the default value is the empty string “”, so the input area initially appears empty.

    The remainder of this assignment statement causes the text entered by the user to be remembered under the name on the left side of the equals sign. In programming terminology, a variable is a name that is given to an arbitrary value so that the value can be remembered and referred to later. In this example, the text entered by the user is assigned to the variable name firstName, and any subsequent references to firstName will recall the user’s text.

    In general, the user can be prompted for any value and that value remembered using a JavaScript assignment statement of the form:

    variable = prompt(“prompt string”, “”);

  • The second JavaScript statement in the above example displays a message in the page that incorporates the user’s name. document.write(“Hello ” + firstName + “, welcome to my Web page.”);This type of JavaScript statement is known as a write statement since it utilizes the predefined document.write function to display the message in the Web page. The message displayed by document.write can be a string (sequence of characters in quotes), or a combination of strings and variables connected with ‘+’, which concatenates (joins end-to-end) the pieces together. Wherever avariable name appears in the message, its corresponding value will be substituted. For example, if “Dave” had been entered and stored in the variable firstName, then the above write statement would write the message

    Hello Dave, welcome to my Web page.into the HTML document. When the page is displayed in the browser, this message will appear along with any other text in the HTML document.

    In general, any message can be written to an HTML document and thus displayed in the page using a JavaScript write statement of the form:

    document.write(“message to be displayed”);

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.


Let us write that nagging essay.


Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.


Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.


Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.


Receive your Paper

After Editing, your paper will be sent to you via email.

× How can I help you?