36
BIT05206 DHTML

Dhtml chapter2

Embed Size (px)

DESCRIPTION

dhtml

Citation preview

Page 1: Dhtml chapter2

BIT05206

DHTML

Page 2: Dhtml chapter2

DHTML

• DHTML is a combination of technologies used to create dynamic and interactive Web sites.

– HTML - For creating text and image links and other page elements.

– CSS - Style Sheets for further formatting of text and html plus other added features such as positioning and layering content.

– JavaScript - The programming language that allows you to accesses and dynamically control the individual properties of both HTML and Style Sheets

Page 3: Dhtml chapter2

Why DHTML

• With DHTML you can create:– Animation– Pop-up menus– Inclusion of Web page content from external

data sources– Elements that can be dragged and dropped

within the Web page

Page 4: Dhtml chapter2
Page 5: Dhtml chapter2

HTML (Hyper Text Markup Language)

• An HTML file is a text file containing small markup tags

• The markup tags tell the Web browser how to display the page

• An HTML file must have an htm or html file extension

• An HTML file can be created using a simple text editor

Page 6: Dhtml chapter2

<html><head>

<title>BIT05206-Lab1</title>

</head><body>

This is Our First Test.<I>This text is Italic</I>

</body></html>• Most tags have opening and closing tags:

<html> </html>, <head> </head>• Only some don’t have it: <br>, <hr>, <img>

HTML (cont.)

gives technical information about the document, and specifies its title. Nothing that appears in the header section will be displayed by the browser.

Page 7: Dhtml chapter2

HTML

Page 8: Dhtml chapter2

HTML

• Some tags have attribute such as:<body bgcolor = “green">– Attributes always come in name/value

pairs like this: name="value". • Find out more of HTML Tags and their

attributes• Special treatment for some characters

&nbsp, &quot

Page 9: Dhtml chapter2

<html><head><title>BIT05206 Lab1</title></head>

<body bgcolor =Red><p align =center> <B> User Interface Design </B></p><hr><p>[1] Course Notes<br>

<a href="http://www.ucc.ac.tz"> BIT05206</a></p>

</body></html>

HTML

Page 10: Dhtml chapter2

HTML

Page 11: Dhtml chapter2

Try it<body><p>Student Marks<br> </p><table width="100%" border="2"> <tr bgcolor="green"> <td>Student Number</td> <td>Student First Name </td> <td>Mark</td> </tr> <tr> <td>10</td> <td>Lily</td> <td>A+</td> </tr> <tr> <td>20</td> <td>Den</td> <td>C+</td> </tr></table></body>

Page 12: Dhtml chapter2

HTML

Page 13: Dhtml chapter2
Page 14: Dhtml chapter2

CSS• CSS stands for Cascading Style

Sheets

• Styles define how to display HTML elements

• Styles are normally stored in Style Sheets

Page 15: Dhtml chapter2

CSS

• External Style Sheets can save you a lot of work

• External Style Sheets are stored in CSS files • Multiple style definitions will cascade into one • Why? Modularity simplicity, usability,

reusability, etc

Page 16: Dhtml chapter2

CSS• Syntax

– selector {property: value} • The selector is normally the HTML element/tag • the property is the attribute you wish to change, • and each property can take a value.

• Three Method to specify– Tag Modfier

– body {color: black} – p { text-align: center; color: black;

font-family: arial }

Page 17: Dhtml chapter2

CSS• Three Method to specify

– Class Modifier• With the class selector you can define different

styles for the same type of HTML element .center {text-align: center}

<h1 class="center"> This heading will be center-aligned

</h1>

– The id Selector • With the id selector you can define the same style

for different HTML elements • #green {color: green}

<h1 id="green">Hello </h1> <p id="green">Some text</p>

Page 18: Dhtml chapter2

CSS (cont.)• How to Insert a Style Sheet

– Internal style • An internal style sheet should be used when a

single document has a unique style. • You define internal styles in the head section by

using the <style>

– Inline Styles: Many of the Advantages are lost

Page 19: Dhtml chapter2

CSS Example<Html>

<head><style type="text/css">

hr {color: green}p {margin-left: 20px}body {background-color:yellow}

</style></head><body>

<h1 style ="color =blue; text-align=center"> BIT05206 </h1><hr><p>DHTML tutorial</p>

</body></Html>

Tag Modifier

Inline

Page 20: Dhtml chapter2

CSS Example

Page 21: Dhtml chapter2

CSS (cont.)• How to Insert a Style Sheet

– External Style Sheet ideal when the style is applied to many pages

<head> <link rel="stylesheet" type="text/css“ href="mystyle.css" />

</head>

.css text file

Page 22: Dhtml chapter2

CSS example

Page 23: Dhtml chapter2

CSS

• Click for more details:

CSS Tutorial.

Page 24: Dhtml chapter2
Page 25: Dhtml chapter2

JavaScript Introduction

• JavaScript was designed to add interactivity to HTML pages

• JavaScript is a scripting language (a scripting language is a lightweight programming language)

• JavaScript embedded in a web browser connects through interfaces called Document Object Models (DOMs) to applications server-side and client-side. This allows interactivity and dynamicity.

Page 26: Dhtml chapter2

JavaScript Introduction

• A JavaScript is usually embedded directly into HTML pages

• JavaScript is an interpreted language (means that scripts execute without preliminary compilation)

Page 27: Dhtml chapter2

How to Put a JavaScript Into an HTML Page

• Scripts in the body section: – Scripts to be executed when the

page loads go in the body section..

<html>

<body>

<script type="text/javascript"> document.write("Hello World!")

</script>

</body>

</html>

Page 28: Dhtml chapter2

Java Script

• Scripts in the head section:– Scripts to be executed when they are called,

or when an event is triggered, go in the head section.

<html>

<head>

<script type="text/javascript">

……..

</script>

</head>

</html>

Page 29: Dhtml chapter2

Java Script

• External JavaScript – Save the external JavaScript file with a .js file

extension <script src="xxx.js"> </script>

• Deals with web elements using Java command,– If statement– Variables– Loops– …….

Page 30: Dhtml chapter2

JavaScript Examples<Html>

<body>

<script type="text/javascript">

var d=new Date()

var timeh=d.getHours()

var timem=d.getMinutes()

document.bgColor=“red”

document.write("the time is: ")

document.write(timeh)

document.write(":")

document.write(timem)

if (timeh>=12)

document.write(" PM")

else

document.write(" AM")

</script>

</body>

Page 31: Dhtml chapter2

JavaScript – function

<html><head><script type="text/javascript">function message(){

alert("Welcome guest!")}</script></head>

<body><input type="button" value="View message" onclick="message()" /></body>

</html>

Page 32: Dhtml chapter2

Java Script and DOM<html>

<body><h1 id="header">My header</h1>

<script type="text/javascript">document.getElementById('header').style.color="red"

</script><p><b>Note:</b> It is the script that changes the style of the element!</p></body></html>

Page 33: Dhtml chapter2

More About DOM

http://www.w3schools.com/htmldom/default.asp

Page 34: Dhtml chapter2

Example Try it<html><head><script type="text/javascript">function hide(){

document.getElementById('txt1').style.visibility ='hidden'}

function show(){

document.getElementById('txt1').style.visibility = 'visible'}

function format(){

document.getElementById('txt1').style.color = 'red'document.getElementById('txt1').style.fontSize = '20'document.getElementById('txt1').style.textAlign ="center"document.bgColor='green'

}

Page 35: Dhtml chapter2

Example (Cont)

function reset(){

document.getElementById('txt1').style.color = 'black'document.getElementById('txt1').style.fontSize = '14'document.getElementById('txt1').style.visibility = 'visible'document.bgColor='white'document.getElementById('txt1').style.textAlign ="left"

}

</script</head><body>

<input type="text" id= "txt1"><input type="button" value="Hide" onclick="hide()"><input type="button" value="show" onclick="show()"><input type="button" value="format" onclick="format()"><input type="button" value="Reset" onclick="reset()">

</body></html>

Page 36: Dhtml chapter2

Next: go through all the examples and try them