Table of Contents

~~SLIDESHOW~~

Dynamic Documents with JavaScript

Lecture 10: To be given on Monday 7th March, 2011.

Lecturer: Dr Chris P. Jobling.

A dynamic HTML document is one whose tag attributes, tag contents, or element style properties can be changed after the document has been and is still being displayed by a browser

Dynamic Documents with JavaScript

Informally, a dynamic XHTML document is one that in some way can be changed while it is being displayed by a browser. The most common client-side approach to providing dynamic documents is with JavaScript. Changes to documents can occur when explicitly requested by user interactions, or at regular timed intervals.


This lecture is based on Chapter 6 of Robert W. Sebasta, Programming the World-Wide Web, 3rd Edition, Addison Wesley, 2006. with additional material from Chapter 8 of Chris Bates, Web Programming: Building Internet Applications, 3rd Edition, John Wiley, 2006.

You should review the notes on CSS for layout before you dive into this lecture.

Contents of this Lecture

An introduction to Dynamic HTML

Contents of this Lecture (2)

Reacting to the mouse

Learning Outcomes

At the end of this lecture you should be able to answer these questions:

Learning Outcomes

At the end of this lecture you should be able to answer these questions:

Learning Outcomes (continued)

At the end of this lecture you should be able to answer these questions:

Moving Elements


<source http://www.cpjobling.me/eg-259/examples/lecture10/mover.html javascript|mover.html>

Element Visibility

    if (dom.visibility == "visible")
      dom.visibility = "hidden";
    else
      dom.visibility = "visible"; 

<source http://www.cpjobling.me/eg-259/examples/lecture10/showHide.html javascript|showHide.html>

Dynamic Colours


<note> Background color:

   <input type = "text" size = "10"
         name = "background"
         onchange = "setColor('background', this.value)"> 

</note>

<source http://www.cpjobling.me/eg-259/examples/lecture10/dynColors.html javascript|dynColors.html>

Dynamically Changing Fonts

	onmouseover = "this.style.color = 'blue';
	      this.style.font = 'italic 16pt Times';"
	onmouseout = "this.style.color = 'black';
	      this.style.font = 'normal 16pt Times';" 

<source http://www.cpjobling.me/eg-259/examples/lecture10/dynLink.html html|dynLink.html>

Dynamic Content


<source http://www.cpjobling.me/eg-259/examples/lecture10/dynValue.html javascript|dynValue.html>

Stacking Elements

Stacking Elements (continued)

    <a href = "javascript:fun()"> 

Stacking Elements (continued)


<source http://www.cpjobling.me/eg-259/examples/lecture10/stacking.html javascript|stacking.html>

Locating the Mouse Cursor


<source http://www.cpjobling.me/eg-259/examples/lecture10/where.html javascript|where.html>

Reacting to a Mouse Click


<source http://www.cpjobling.me/eg-259/examples/lecture10/anywhere.html javascript|anywhere.html>

Slow Movement of Elements

    setTimeout("fun()", n)

Slow Movement of Elements: An Example


<note>

</note>

<source http://www.cpjobling.me/eg-259/examples/lecture10/moveText.html html|moveText.html>

<source http://www.cpjobling.me/eg-259/examples/lecture10/moveTextfuns.js javascript|moveTextfuns.js>

Dragging and Dropping an Element

Dragging and Dropping an Element (continued)


<source http://www.cpjobling.me/eg-259/examples/lecture10/dragNDrop.html javascript|dragNDrop.html>

Dragging and Dropping an Element (continued)

Summary of This Lecture

An introduction to Dynamic HTML

Summary of This Lecture (2)

Reacting to the mouse

Learning Outcomes

At the end of this lecture you should be able to answer these questions:

Learning Outcomes (continued)

Learning Outcomes (continued)

At the end of this lecture you should be able to answer these questions:

Exercises (1)

Write, test, validate, and debug (if necessary) the following documents:

Exercises (2)

Write, test, validate, and debug (if necessary) the following documents:

Exercises (3)

Write, test, validate, and debug (if necessary) the following documents:

More Homework Exercises

More Dynamic HTML exercises, taken from Chapter 6 of Chris Bates, Web Programming: Building Internet Applications, 3rd Edition, John Wiley, 2006., are available.

What's Next?

JavaScript Libraries

Previous Lecture | home | Next Lecture