SlideShare a Scribd company logo
BIT05206 
DHTML
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
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
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
<html> 
<head> 
HTML (cont.) 
<title>BIT05206-Lab1</title> 
</head> 
<body> 
This is Our First Test. 
<I>This text is Italic</I> 
gives technical information 
about the document, and 
specifies its title. Nothing 
that appears in the header 
section will be displayed by 
the browser. 
</body> 
</html> 
• Most tags have opening and closing tags: 
<html> </html>, <head> </head> 
• Only some don’t have it: <br>, <hr>, <img>
HTML
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
<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
HTML
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>
HTML
Dhtml chapter2
CSS 
• CSS stands for Cascading Style 
Sheets 
• Styles define how to display HTML 
elements 
• Styles are normally stored in Style 
Sheets
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
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 }
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>
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
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
CSS Example
CSS (cont.) 
• How to Insert a Style Sheet 
– External Style Sheet ideal when the style is 
applied to many pages 
.css text 
file 
<head> 
<link rel="stylesheet" type="text/css“ href="mystyle.css" /> 
</head>
CSS example
CSS 
• Click for more details: 
CSS Tutorial.
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.
JavaScript Introduction 
• A JavaScript is usually embedded directly into 
HTML pages 
• JavaScript is an interpreted language (means 
that scripts execute without preliminary 
compilation)
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>
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>
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 
– …….
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>
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>
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>
More About DOM 
http://www.w3schools.com/htmldom/default.asp
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' 
}
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>
Next: go through all the 
examples and try them

More Related Content

PPTX
DHTML
Ravinder Kamboj
 
PPT
Dhtml
Soham Sengupta
 
PPTX
Dhtml
rahul kundu
 
PPT
Unit 2 dhtml
Sarthak Varshney
 
PPTX
Dhtml sohaib ch
Sohaib Chaudhery
 
PPTX
Dhtml
Sadhana28
 
PPTX
13. session 13 introduction to dhtml
Phúc Đỗ
 
Unit 2 dhtml
Sarthak Varshney
 
Dhtml sohaib ch
Sohaib Chaudhery
 
Dhtml
Sadhana28
 
13. session 13 introduction to dhtml
Phúc Đỗ
 

What's hot (19)

PPT
DHTML - Dynamic HTML
Reem Alattas
 
PPTX
Dynamic HTML (DHTML)
Himanshu Kumar
 
PPTX
Html and dhtml
Laxmihhar Basti
 
PPTX
Introduction to DOM
Daniel Bragais
 
PPT
Document Object Model
chomas kandar
 
PPTX
Html n CSS
Sukrit Gupta
 
PPTX
Understanding the dom by Benedict Ayiko
Damalie Wasukira
 
PPTX
Web Design L1 - Untagling the Web
mykella
 
PPTX
Document Object Model
Mayur Mudgal
 
PPTX
Document object model(dom)
rahul kundu
 
PDF
Lab#2 overview of html
Yaowaluck Promdee
 
PPTX
Hushang Gaikwad
Hushnag Gaikwad
 
PPTX
An Introduction to the DOM
Mindy McAdams
 
PPT
Introduction css
sagaroceanic11
 
PPS
Xhtml
Samir Sabry
 
PPTX
15. session 15 data binding
Phúc Đỗ
 
PPTX
The Document Object Model
Khou Suylong
 
PPTX
11 Quiz related to HTML, CSS, JS and WP
Rashna Maharjan
 
DHTML - Dynamic HTML
Reem Alattas
 
Dynamic HTML (DHTML)
Himanshu Kumar
 
Html and dhtml
Laxmihhar Basti
 
Introduction to DOM
Daniel Bragais
 
Document Object Model
chomas kandar
 
Html n CSS
Sukrit Gupta
 
Understanding the dom by Benedict Ayiko
Damalie Wasukira
 
Web Design L1 - Untagling the Web
mykella
 
Document Object Model
Mayur Mudgal
 
Document object model(dom)
rahul kundu
 
Lab#2 overview of html
Yaowaluck Promdee
 
Hushang Gaikwad
Hushnag Gaikwad
 
An Introduction to the DOM
Mindy McAdams
 
Introduction css
sagaroceanic11
 
15. session 15 data binding
Phúc Đỗ
 
The Document Object Model
Khou Suylong
 
11 Quiz related to HTML, CSS, JS and WP
Rashna Maharjan
 
Ad

Similar to Dhtml chapter2 (20)

PPTX
Unit 1wt
vamsitricks
 
PPTX
Unit 1wt
vamsi krishna
 
PPTX
1812010023 web developement(ANKITA OJHA)CSE4(A).pptx
HarshJaiswal535013
 
PDF
Introduction to Bootstrap
Ron Reiter
 
PPTX
HTML CSS by Anubhav Singh
Anubhav659
 
PDF
What is HTML - An Introduction to HTML (Hypertext Markup Language)
Ahsan Rahim
 
PPT
LIS3353 SP12 Week 4
Amanda Case
 
PPTX
Basics of html for web development by software outsourcing company india
Jignesh Aakoliya
 
PPTX
Intro to CSS_APEC CascadingStyleSheets.pptx
stephysnscphysio
 
PPTX
Hypertext markup language(html)
Jayson Cortez
 
PDF
Day1-HTML-CSS some basic css and html.pdf
enasashri12
 
DOCX
Caracteristicas Basicas De Htlm
Maria S Rivera
 
PPTX
Additional HTML
Doeun KOCH
 
PPTX
Html css java script basics All about you need
Dipen Parmar
 
PPTX
HTML Basic, CSS Basic, JavaScript basic.
Beqa Chacha
 
PPTX
BITM3730 9-12.pptx
MattMarino13
 
PPTX
POLITEKNIK MALAYSIA
Aiman Hud
 
PPTX
4. html css-java script-basics
Nikita Garg
 
Unit 1wt
vamsitricks
 
Unit 1wt
vamsi krishna
 
1812010023 web developement(ANKITA OJHA)CSE4(A).pptx
HarshJaiswal535013
 
Introduction to Bootstrap
Ron Reiter
 
HTML CSS by Anubhav Singh
Anubhav659
 
What is HTML - An Introduction to HTML (Hypertext Markup Language)
Ahsan Rahim
 
LIS3353 SP12 Week 4
Amanda Case
 
Basics of html for web development by software outsourcing company india
Jignesh Aakoliya
 
Intro to CSS_APEC CascadingStyleSheets.pptx
stephysnscphysio
 
Hypertext markup language(html)
Jayson Cortez
 
Day1-HTML-CSS some basic css and html.pdf
enasashri12
 
Caracteristicas Basicas De Htlm
Maria S Rivera
 
Additional HTML
Doeun KOCH
 
Html css java script basics All about you need
Dipen Parmar
 
HTML Basic, CSS Basic, JavaScript basic.
Beqa Chacha
 
BITM3730 9-12.pptx
MattMarino13
 
POLITEKNIK MALAYSIA
Aiman Hud
 
4. html css-java script-basics
Nikita Garg
 
Ad

More from FLYMAN TECHNOLOGY LIMITED (20)

PPTX
Flyman Technology Limited Introduction Presentation
FLYMAN TECHNOLOGY LIMITED
 
PDF
Flyman Technology Limited (Mzumbe University Tanzania)
FLYMAN TECHNOLOGY LIMITED
 
PDF
Flyman Technology Limited Tanzania
FLYMAN TECHNOLOGY LIMITED
 
PPTX
Saadani national park 2015
FLYMAN TECHNOLOGY LIMITED
 
PDF
Uuzaji wa mazao ya kuku wa asili
FLYMAN TECHNOLOGY LIMITED
 
PDF
Entrepreneurship manual BIT
FLYMAN TECHNOLOGY LIMITED
 
PPT
Security chapter6
FLYMAN TECHNOLOGY LIMITED
 
PPT
introduction to the document object model- Dom chapter5
FLYMAN TECHNOLOGY LIMITED
 
PPT
internet intranet and extranet
FLYMAN TECHNOLOGY LIMITED
 
PPT
introduction to web application development
FLYMAN TECHNOLOGY LIMITED
 
PPTX
Marketing management
FLYMAN TECHNOLOGY LIMITED
 
PPTX
Marketing communications
FLYMAN TECHNOLOGY LIMITED
 
PPT
Marketing analysis
FLYMAN TECHNOLOGY LIMITED
 
PPTX
Market segmentation
FLYMAN TECHNOLOGY LIMITED
 
PPT
Consumer markets
FLYMAN TECHNOLOGY LIMITED
 
PDF
ENTREPRENEURSHIP MANUAL
FLYMAN TECHNOLOGY LIMITED
 
PPTX
THINGS NOT TO DO IN A JOB INTERVIEW!
FLYMAN TECHNOLOGY LIMITED
 
PPT
TAXATION CONCEPTS
FLYMAN TECHNOLOGY LIMITED
 
PDF
Html tutorial
FLYMAN TECHNOLOGY LIMITED
 
PPTX
SYSTEM MODELLING
FLYMAN TECHNOLOGY LIMITED
 
Flyman Technology Limited Introduction Presentation
FLYMAN TECHNOLOGY LIMITED
 
Flyman Technology Limited (Mzumbe University Tanzania)
FLYMAN TECHNOLOGY LIMITED
 
Flyman Technology Limited Tanzania
FLYMAN TECHNOLOGY LIMITED
 
Saadani national park 2015
FLYMAN TECHNOLOGY LIMITED
 
Uuzaji wa mazao ya kuku wa asili
FLYMAN TECHNOLOGY LIMITED
 
Entrepreneurship manual BIT
FLYMAN TECHNOLOGY LIMITED
 
Security chapter6
FLYMAN TECHNOLOGY LIMITED
 
introduction to the document object model- Dom chapter5
FLYMAN TECHNOLOGY LIMITED
 
internet intranet and extranet
FLYMAN TECHNOLOGY LIMITED
 
introduction to web application development
FLYMAN TECHNOLOGY LIMITED
 
Marketing management
FLYMAN TECHNOLOGY LIMITED
 
Marketing communications
FLYMAN TECHNOLOGY LIMITED
 
Marketing analysis
FLYMAN TECHNOLOGY LIMITED
 
Market segmentation
FLYMAN TECHNOLOGY LIMITED
 
Consumer markets
FLYMAN TECHNOLOGY LIMITED
 
ENTREPRENEURSHIP MANUAL
FLYMAN TECHNOLOGY LIMITED
 
THINGS NOT TO DO IN A JOB INTERVIEW!
FLYMAN TECHNOLOGY LIMITED
 
TAXATION CONCEPTS
FLYMAN TECHNOLOGY LIMITED
 
SYSTEM MODELLING
FLYMAN TECHNOLOGY LIMITED
 

Recently uploaded (20)

PDF
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
PPTX
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Make GenAI investments go further with the Dell AI Factory - Infographic
Principled Technologies
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
PDF
DevOps & Developer Experience Summer BBQ
AUGNYC
 
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
AbdullahSani29
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Make GenAI investments go further with the Dell AI Factory - Infographic
Principled Technologies
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
DevOps & Developer Experience Summer BBQ
AUGNYC
 
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
AbdullahSani29
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Software Development Methodologies in 2025
KodekX
 
This slide provides an overview Technology
mineshkharadi333
 

Dhtml chapter2

  • 2. 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
  • 3. 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
  • 5. 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
  • 6. <html> <head> HTML (cont.) <title>BIT05206-Lab1</title> </head> <body> This is Our First Test. <I>This text is Italic</I> gives technical information about the document, and specifies its title. Nothing that appears in the header section will be displayed by the browser. </body> </html> • Most tags have opening and closing tags: <html> </html>, <head> </head> • Only some don’t have it: <br>, <hr>, <img>
  • 8. 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
  • 9. <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
  • 10. HTML
  • 11. 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>
  • 12. HTML
  • 14. CSS • CSS stands for Cascading Style Sheets • Styles define how to display HTML elements • Styles are normally stored in Style Sheets
  • 15. 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
  • 16. 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 }
  • 17. 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>
  • 18. 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
  • 19. 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
  • 21. CSS (cont.) • How to Insert a Style Sheet – External Style Sheet ideal when the style is applied to many pages .css text file <head> <link rel="stylesheet" type="text/css“ href="mystyle.css" /> </head>
  • 23. CSS • Click for more details: CSS Tutorial.
  • 25. 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.
  • 26. JavaScript Introduction • A JavaScript is usually embedded directly into HTML pages • JavaScript is an interpreted language (means that scripts execute without preliminary compilation)
  • 27. 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>
  • 28. 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>
  • 29. 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 – …….
  • 30. 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>
  • 31. 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>
  • 32. 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>
  • 33. More About DOM http://www.w3schools.com/htmldom/default.asp
  • 34. 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' }
  • 35. 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>
  • 36. Next: go through all the examples and try them