SlideShare a Scribd company logo
1 of 52
HTML
Concepts and Techniques
Fifth Edition
Chapter 9
Integrating JavaScript
and HTML
Chapter 9: Integrating JavaScript and HTML 2
Chapter Objectives
• Understand the concept of JavaScript language.
• Discuss how to integrate JavaScript and HTML
• Insert <script> tags on a Web page
• Define and describe JavaScript variables
• Extract the current system date
• Calculate the number of days from the current
date to a future date
Chapter 9: Integrating JavaScript and HTML 3
Chapter Objectives
• Describe the write() method of the document
object
• Save the HTML file and test the Web page
• Write a dynamic message to a Web page
• Write a user-defined function that changes the
color of the browser’s scroll bar
Chapter 9: Integrating JavaScript and HTML 4
Chapter Objectives
• Construct a URL from a select list option choice
• Use the document’s location property to link to
a new Web page
• Use the lastModified property to display the last
modified document date
Chapter 9: Integrating JavaScript and HTML 5
Introduction
• JavaScript is an event driven, object-based, programming
language that provides various types of functionality to
Web pages, such as the ability to interact with the user.
• An event driven programming language is one that
responds to events, such as user clicking a Submit or
Calculate button.
• JavaScript is object-based because it is a scripting
language that uses built-in objects that belong to the
browser.
• An object is a person, place, or thing
Built-in JavaScript Objects
• Built-in object are values that are common to a browser
(array, dates, strings etc.) and neither depend on nor
belong to another object.
• Table 9-1 contains a general list of the built-in JavaScript
objects common to many browsers
• JavaScript developers can create new objects based on
the built-in objects and the new object inherit properties
from the original objects.
• JavaScript objects have properties and methods.
Chapter 9: Integrating JavaScript and HTML 6
Table 9-1 Built-in JavaScript Objects
Object Description
Array Return an ordered set of values
Boolean Convert objects to Boolean values
Date Accesses the system time and date
Document Represent s the content of a browser’s window
Form Represents forms created with the <form> tag
Function Accesses information about specific functions
History Keeps track of Web pages visited
Image Represents images created with the <img> tag
Location Switches to a new Web page
Math Performs calculations
Navigator Obtain information about the current Web browser
Number Support special constants
Screen Gives platform specific information about the user screen
String Represents a set of character
Windows and Frames Represent a browser windows or every frame within a browser windows
Chapter 9: Integrating JavaScript and HTML 7
Object and Property
• Properties are attributes of objects and describe an
object’s characteristics.
• Table 9-2 shown an object and property are written by
separating the object form its property with a period.
• A specific value can be assigned to a property as shown
in the following example:
dog.breed=“terrier”
where the dog is the object, breed is the property, and
terrier is the value assigned to the property.
Chapter 9: Integrating JavaScript and HTML 8
Table 9-2 Object and Property
General Form : object.property
Comment : Where the object is stated first, then a period,
then the descriptive property. A value can be
assigned to the property, or the property can
return a value as shown in the example below.
Examples: document.bgColor=“lightblue”
browser=navigator.appName
Chapter 9: Integrating JavaScript and HTML 9
Object and Method
• Methods are actions that an object can perform
• For example, methods associated with the dog object
might be eat, fetch, and sit up. An object and one of its
methods would be written as:
dog.fetch()
where the dog is the object and fetch is a method of the
dog object
• Methods are followed by parentheses which may be
empty or may contain an argument.
Chapter 9: Integrating JavaScript and HTML 10
Object and Argument
• An argument is a value given to a method.
• Some methods require arguments, and others do not.
• For example, given a dog object and fetch() method, a
statement could be written as:
dog.fetch(“ball”)
where the argument “ball” describes what the dog fetches.
• As shown in Table 9-3, the general form of writing an
object with its method is similar to writing object and
properties.
Chapter 9: Integrating JavaScript and HTML 11
Table 9-3 Object and Method
General Form : objectname.method(argument value)
Comment : Where objectname is the object, method is the
action, and parameters are optional items or
instructions should use. A period separates the
object name from the property or method name
Examples: document.write(“some text”)
window.alert(“This is a message”)
varToDayDate=Date.toString()
Chapter 9: Integrating JavaScript and HTML 12
User-Defined Functions
• A user-defined function is JavaScript code written by
developer to perform a particular task.
• The function can be used whenever the task is needed,
eliminating the need to repeat the code several times
throughout an application.
• JavaScript also contains a number of built-in functions
called global functions such as:
– close() – to close a window
– open() – to open a window
– print() – to print the contents of a windows
• Most of these functions actually belong to the window
object, but because the window object is assumed, they
are called built-in functions
Chapter 9: Integrating JavaScript and HTML 13
• For a complete list of built-in functions, see the JavaScript
Quick Reference in Appendix E.
• Most JavaScript user-defined functions are called or
activated using event-handler.
• An event is the result of an action, such as mouse click or
a document loading.
• An event handler is JavaScript’s way to associate an
action with a function.
• In this project, you first write the functions, and then event
handlers that will associate the functions with specific
events, such as loading the Web page.
Chapter 9: Integrating JavaScript and HTML 14
Chapter 9: Integrating JavaScript and HTML 15
Opening an HTML File
• Start Notepad, and, if necessary, maximize the window.
Click Format on the menu bar. If the Word Wrap command
does not have a check mark next to it, click Word Wrap
• With a USB flash drive connected to one of the computer’s
USB ports, click File on the menu bar and then click Open
• If Computer is not displayed in the Favorite Links section,
drag the top or bottom edge of the Open dialog box until
Computer is displayed
Chapter 9: Integrating JavaScript and HTML 16
Opening an HTML File
• Click Computer in the Favorite Links section to display a
list of available drives
• If necessary, scroll until UDISK 2.0 (G:) appears in the list
of available drives
• Double-click USB drive (G:). Open the Chapter09 folder,
and then double-click the ChapterFiles folder in the list of
available folders
• If necessary, click the Files of type box arrow, and then
click All Files. Click chapter09.html in the list of files
• Click the Open button in the Open dialog box to display
the HTML code for the chapter09.html Web page
Chapter 9: Integrating JavaScript and HTML 17
Opening an HTML File
Chapter 9: Integrating JavaScript and HTML 18
Entering the Start <script>
and Comment Tags
• Click the blank line (line 32) press the spacebarto indent
as shown below the <p style=“margin-left:10%”> tag
• Type <script type="text/javascript"> as the
beginning of the script and then press the ENTER key
• Type <!--Hide from old browsers and then press
the ENTER key
Chapter 9: Integrating JavaScript and HTML 19
Entering the Start <script>
and Comment Tags
Chapter 9: Integrating JavaScript and HTML 20
Extracting the Current System Date
Using the Date() Object
• If necessary, click the chapter 09 - Notepad button on the
taskbar to activate the Notepad window
• Click line 41 below the <!--Hide from old browsers
statement
• Enter the JavaScript code shown in Table 9–13. Press
ENTER at the end of each complete line of code. Enter
the current year in the indexOf() method on line 48
• After typing the last line in Table 9–13, press the ENTER
key once more to leave space for additional JavaScript
code
Chapter 9: Integrating JavaScript and HTML 21
Extracting the Current System Date
Using the Date() Object
Chapter 9: Integrating JavaScript and HTML 22
Creating a Date() Object Instance to Store a
Future Date
• Click line 51
• Substituting the
current year for the
spring date March 21,
2010, type var
springDate = new
Date("March 21,
2010) to set the
date to the start of
spring and then press
the ENTER key
Chapter 9: Integrating JavaScript and HTML 23
Calculating Milliseconds Between Two
Dates Using the getTime() Method
• Click line 52, if
necessary
• Type var daysToGo
= springDate.
getTime()-today.
getTime() to
calculate the number
of milliseconds and
then press the ENTER
key
Chapter 9: Integrating JavaScript and HTML 24
Converting Milliseconds to Days and
Rounding Up Using the ceil() Method
• Click line 53, if
necessary
• Type var
daysToSpring =
Math.ceil(daysTo
Go/
(1000*60*60*24))
to convert
milliseconds to days
and then press the
ENTER key twice
Chapter 9: Integrating JavaScript and HTML 25
Writing Text and Variable Values
to a Web Page
• Click line 55, if necessary
• Enter the JavaScript code shown in Table 9–16 to
concatenate the message text with the stored values.
Press the ENTER key only at the end of each complete
line of code
• Press the ENTER key an additional time after line 57
Chapter 9: Integrating JavaScript and HTML 26
Writing Text and Variable Values
to a Web Page
Chapter 9: Integrating JavaScript and HTML 27
Entering the End Comment and
</script> Tags
• If necessary, click blank line 59
• Enter the following JavaScript code and do not press the
ENTER key after the last line
Chapter 9: Integrating JavaScript and HTML 28
Entering the End Comment and
</script> Tags
Chapter 9: Integrating JavaScript and HTML 29
Saving an HTML File
• With a USB flash drive connected to one of the computer’s USB
ports, click File on the Notepad menu bar and then click Save As.
Type chapter09westlake.html in the File name text box (do
not press the ENTER key)
• If Computer is not displayed in the Favorite Links section, drag the
top or bottom edge of the Save As dialog box until Computer is
displayed
• Click Computer in the Favorite Links section to display a list of
available drives
• If necessary, scroll until UDISK 2.0 (G:) appears in the list of
available drives
• If necessary, open the Chapter09ChapterFiles folder
• Click the Save button in the Save As dialog box to save the file on
the USB flash drive with the name chapter09westlake.html
Chapter 9: Integrating JavaScript and HTML 30
Saving an HTML File
Chapter 9: Integrating JavaScript and HTML 31
Testing the JavaScript on a Web Page
• Click the Start button on the Windows Vista taskbar to
display the Start menu
• Click Internet Explorer (or another browser icon) on the
Start menu. If necessary, click the Maximize button to
maximize the browser window
• Click the Address bar to select the URL on the Address
bar
• Type
g:Chapter09ChapterFileschapter09westlake.html
in the Address box.
• Press ENTER to display the Web page
Testing the JavaScript on a Web Page
Chapter 9: Integrating JavaScript and HTML 32
Chapter 9: Integrating JavaScript and HTML 33
Including the Date Last Modified
in a Text String
• If necessary, click the Notepad button on the taskbar to
activate the Notepad window
• Click line 91 below the second <p> </p> paragraph tag
after the closing </table> tag
• Enter the JavaScript code shown in Table 9–19. Press
the ENTER key after each line but not after the last
</script> line
Chapter 9: Integrating JavaScript and HTML 34
Including the Date Last Modified
in a Text String
Chapter 9: Integrating JavaScript and HTML 35
Entering User-Defined Functions
in the <head> Section
• If necessary, click the chapter09westlake.html –
Notepad icon on the taskbar
• Click blank line 6 directly below the <title> tags
• Enter the JavaScript code shown in Table 9–23
• Press the ENTER key twice after the last } to leave a
blank line between user-defined functions
Chapter 9: Integrating JavaScript and HTML 36
Entering User-Defined Functions
in the <head> Section
Entering the User-defined Function to Link to a
new URL using the Drop-Down Menu List
• Click line 14 if necessary
• Enter the JavaScript code shown in Table 9–26 to enter
the options and links for the drop-down menu list
• Do not press the ENTER key after the last line
Chapter 9: Integrating JavaScript and HTML 37
Entering the User-defined Function to Link to a
new URL using the Drop-Down Menu List
Chapter 9: Integrating JavaScript and HTML 38
Chapter 9: Integrating JavaScript and HTML 39
Associating a User-Defined Function
with the onLoad Event
• Click to the right of the y in the <body> tag in line 34
• Press the SPACEBAR once and then type
onLoad=“scrollColor()”
within the <body> tag. Do not press the ENTER key
Chapter 9: Integrating JavaScript and HTML 40
Associating a User-Defined Function
with the onLoad Event
Chapter 9: Integrating JavaScript and HTML 41
Associating a User-Defined Function
with the Select List
• Click to the right of “Menu” in line 85
• Press the SPACEBAR once and then type
onchange=“loadInfo(this.form)“
within the <select> tag. Do not press the ENTER key
Chapter 9: Integrating JavaScript and HTML 42
Associating a User-Defined Function
with the Select List
Chapter 9: Integrating JavaScript and HTML 43
Saving an HTML File and Viewing and
Testing the Completed Web Page
• With the USB drive plugged into your computer, click File
on the menu bar
• Click Save on the File menu
• Click the chapter 09WestLake Landscaping – Windows
Internet Explorer button on the taskbar
• Click the Refresh button on the Standard Buttons toolbar
• Select Rocks and Stones in the dropdown menu list to
display the Rocks and Stones page
Chapter 9: Integrating JavaScript and HTML 44
Saving an HTML File and Viewing and
Testing the Completed Web Page
• Click the Back button on the Standard Buttons toolbar to
return to the West Lake Landscaping page
• Select Using Flowers in the drop-down menu list to
display the Use of Flowers in Landscape Design page
• Click the Home link at the bottom of the page to return to
the West Lake Landscaping home page, and select
Landscape Design Principles from the dropdown menu
list to display the Design Principles page
• Click the Home link at the bottom of the page to return to
the West Lake Landscaping home page
Saving an HTML File and Viewing and
Testing the Completed Web Page
Chapter 9: Integrating JavaScript and HTML 45
Chapter 9: Integrating JavaScript and HTML 46
Validating a Web Page
• Open Internet Explorer and navigate to the Web site
validator.w3.org
• Click the Validate by File Upload tab
• Click the Browse button
• Locate the chapter09westlake.html file on your storage
device and click the file name
• Click the Open button on the Choose file dialog box and
the file name will be inserted into the File box
• Click the Check button
Chapter 9: Integrating JavaScript and HTML 47
Printing an HTML File
• If necessary, click the chapter09westlake.html - Notepad
button on the taskbar
• Click File on the menu bar and then click Print. Click the
Print button in the Print dialog box
Chapter 9: Integrating JavaScript and HTML 48
Quitting Notepad and a Browser
• Click the Close button on the browser title bar
• Click the Close button on the Notepad window title bar
Chapter 9: Integrating JavaScript and HTML 49
Chapter Summary
• Discuss how to integrate JavaScript and HTML
• Insert <script> tags on a Web page
• Define and describe JavaScript variables
• Extract the current system date
• Calculate the number of days from the current
date to a future date
Chapter 9: Integrating JavaScript and HTML 50
Chapter Summary
• Describe the write() method of the document
object
• Save the HTML file and test the Web page
• Write a dynamic message to a Web page
• Write a user-defined function that changes the
color of the browser’s scroll bar
Chapter 9: Integrating JavaScript and HTML 51
Chapter Summary
• Construct a URL from a select list option choice
• Use the document’s location property to link to a
new Web page
• Use the lastModified property to display the last
modified document date
HTML
Concepts and Techniques
Fifth Edition
Chapter 9 Complete
Integrating JavaScript
and HTML

More Related Content

What's hot

Lesson 2 cs5
Lesson 2   cs5Lesson 2   cs5
Lesson 2 cs5dtelepos
 
CHILD Site Coordinator Training
CHILD Site Coordinator TrainingCHILD Site Coordinator Training
CHILD Site Coordinator Trainingehealth
 
06 laboratory exercise 1
06 laboratory exercise 106 laboratory exercise 1
06 laboratory exercise 1Anne Lee
 
Necto 16 training 6 - web component
Necto 16 training 6 -  web componentNecto 16 training 6 -  web component
Necto 16 training 6 - web componentPanorama Software
 
Project 02 Creating and Editing a Web Page
Project 02 Creating and Editing a Web PageProject 02 Creating and Editing a Web Page
Project 02 Creating and Editing a Web PageAngela Edel
 
Pinnacle Cart Design documentation v1.0
Pinnacle Cart Design documentation v1.0Pinnacle Cart Design documentation v1.0
Pinnacle Cart Design documentation v1.0ericssonjohn1
 
Gl13 m4-presentation
Gl13 m4-presentationGl13 m4-presentation
Gl13 m4-presentationTracie King
 
Lesson 5 cs5
Lesson 5   cs5Lesson 5   cs5
Lesson 5 cs5dtelepos
 
Digital Collection Development Presentation #2
Digital Collection Development Presentation #2Digital Collection Development Presentation #2
Digital Collection Development Presentation #2Joyce Kasman Valenza
 
Web technology practical list
Web technology practical listWeb technology practical list
Web technology practical listdesaipratu10
 
Practical file on web technology(html)
Practical file on web technology(html)Practical file on web technology(html)
Practical file on web technology(html)RAJWANT KAUR
 
Gl13 m0-c2-presentation
Gl13 m0-c2-presentationGl13 m0-c2-presentation
Gl13 m0-c2-presentationTracie King
 
Digital colldevel pt2
Digital colldevel pt2Digital colldevel pt2
Digital colldevel pt2Debra Kachel
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 1
Girl Develop It Cincinnati: Intro to HTML/CSS Class 1Girl Develop It Cincinnati: Intro to HTML/CSS Class 1
Girl Develop It Cincinnati: Intro to HTML/CSS Class 1Erin M. Kidwell
 

What's hot (17)

Lesson 2 cs5
Lesson 2   cs5Lesson 2   cs5
Lesson 2 cs5
 
CHILD Site Coordinator Training
CHILD Site Coordinator TrainingCHILD Site Coordinator Training
CHILD Site Coordinator Training
 
06 laboratory exercise 1
06 laboratory exercise 106 laboratory exercise 1
06 laboratory exercise 1
 
Necto 16 training 6 - web component
Necto 16 training 6 -  web componentNecto 16 training 6 -  web component
Necto 16 training 6 - web component
 
Project 02 Creating and Editing a Web Page
Project 02 Creating and Editing a Web PageProject 02 Creating and Editing a Web Page
Project 02 Creating and Editing a Web Page
 
Pinnacle Cart Design documentation v1.0
Pinnacle Cart Design documentation v1.0Pinnacle Cart Design documentation v1.0
Pinnacle Cart Design documentation v1.0
 
php
phpphp
php
 
Gl13 m4-presentation
Gl13 m4-presentationGl13 m4-presentation
Gl13 m4-presentation
 
Lesson 5 cs5
Lesson 5   cs5Lesson 5   cs5
Lesson 5 cs5
 
Digital Collection Development Presentation #2
Digital Collection Development Presentation #2Digital Collection Development Presentation #2
Digital Collection Development Presentation #2
 
Web technology practical list
Web technology practical listWeb technology practical list
Web technology practical list
 
Practical file on web technology(html)
Practical file on web technology(html)Practical file on web technology(html)
Practical file on web technology(html)
 
Different page numbers inserted in one document: A step-by-step guide
Different page numbers inserted in one document: A step-by-step guideDifferent page numbers inserted in one document: A step-by-step guide
Different page numbers inserted in one document: A step-by-step guide
 
Gl13 m0-c2-presentation
Gl13 m0-c2-presentationGl13 m0-c2-presentation
Gl13 m0-c2-presentation
 
Digital colldevel pt2
Digital colldevel pt2Digital colldevel pt2
Digital colldevel pt2
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 1
Girl Develop It Cincinnati: Intro to HTML/CSS Class 1Girl Develop It Cincinnati: Intro to HTML/CSS Class 1
Girl Develop It Cincinnati: Intro to HTML/CSS Class 1
 
Html basics
Html basicsHtml basics
Html basics
 

Similar to Ddpz2613 topic9 java

Necto 16 training 20 component mode &amp; java script
Necto 16 training 20   component mode &amp; java scriptNecto 16 training 20   component mode &amp; java script
Necto 16 training 20 component mode &amp; java scriptPanorama Software
 
javascript Event Handling and introduction to event.ppt
javascript Event Handling and introduction to event.pptjavascript Event Handling and introduction to event.ppt
javascript Event Handling and introduction to event.pptLalith86
 
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32Bilal Ahmed
 
27 - Panorama Necto 14 component mode & java script - visualization & data di...
27 - Panorama Necto 14 component mode & java script - visualization & data di...27 - Panorama Necto 14 component mode & java script - visualization & data di...
27 - Panorama Necto 14 component mode & java script - visualization & data di...Panorama Software
 
introduction to the document object model- Dom chapter5
introduction to the document object model- Dom chapter5introduction to the document object model- Dom chapter5
introduction to the document object model- Dom chapter5FLYMAN TECHNOLOGY LIMITED
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010vchircu
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05Terry Yoast
 

Similar to Ddpz2613 topic9 java (20)

ASP.NET - Web Programming
ASP.NET - Web ProgrammingASP.NET - Web Programming
ASP.NET - Web Programming
 
IP Unit 2.pptx
IP Unit 2.pptxIP Unit 2.pptx
IP Unit 2.pptx
 
Necto 16 training 20 component mode &amp; java script
Necto 16 training 20   component mode &amp; java scriptNecto 16 training 20   component mode &amp; java script
Necto 16 training 20 component mode &amp; java script
 
Javascript projects Course
Javascript projects CourseJavascript projects Course
Javascript projects Course
 
javascript Event Handling and introduction to event.ppt
javascript Event Handling and introduction to event.pptjavascript Event Handling and introduction to event.ppt
javascript Event Handling and introduction to event.ppt
 
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32
 
A View about ASP .NET and their objectives
A View about ASP .NET and their objectivesA View about ASP .NET and their objectives
A View about ASP .NET and their objectives
 
Extjs
ExtjsExtjs
Extjs
 
Html5
Html5Html5
Html5
 
27 - Panorama Necto 14 component mode & java script - visualization & data di...
27 - Panorama Necto 14 component mode & java script - visualization & data di...27 - Panorama Necto 14 component mode & java script - visualization & data di...
27 - Panorama Necto 14 component mode & java script - visualization & data di...
 
Html5
Html5Html5
Html5
 
ASP DOT NET
ASP DOT NETASP DOT NET
ASP DOT NET
 
javascript.pptx
javascript.pptxjavascript.pptx
javascript.pptx
 
javascript.pptx
javascript.pptxjavascript.pptx
javascript.pptx
 
introduction to the document object model- Dom chapter5
introduction to the document object model- Dom chapter5introduction to the document object model- Dom chapter5
introduction to the document object model- Dom chapter5
 
CSC PPT 12.pptx
CSC PPT 12.pptxCSC PPT 12.pptx
CSC PPT 12.pptx
 
Session-4.pptx
Session-4.pptxSession-4.pptx
Session-4.pptx
 
Week8
Week8Week8
Week8
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05
 

More from Mohamad Sahiedan (19)

Cd chap 2 - static loading
Cd   chap 2 - static loadingCd   chap 2 - static loading
Cd chap 2 - static loading
 
Ddpz2613 topic6 frame
Ddpz2613 topic6 frameDdpz2613 topic6 frame
Ddpz2613 topic6 frame
 
Ddpz2613 topic5 image
Ddpz2613 topic5 imageDdpz2613 topic5 image
Ddpz2613 topic5 image
 
Ddpz2613 topic4 table
Ddpz2613 topic4 tableDdpz2613 topic4 table
Ddpz2613 topic4 table
 
Ddpz2613 topic3 linking
Ddpz2613 topic3 linkingDdpz2613 topic3 linking
Ddpz2613 topic3 linking
 
Ddpz2613 topic1 introduction
Ddpz2613 topic1 introductionDdpz2613 topic1 introduction
Ddpz2613 topic1 introduction
 
Doc2
Doc2Doc2
Doc2
 
Tips tassawur islam sha
Tips tassawur islam shaTips tassawur islam sha
Tips tassawur islam sha
 
Bab 2.tauhid paksi kehidupan
Bab 2.tauhid paksi kehidupanBab 2.tauhid paksi kehidupan
Bab 2.tauhid paksi kehidupan
 
Bab 1.konsep ilmu
Bab 1.konsep ilmuBab 1.konsep ilmu
Bab 1.konsep ilmu
 
Bab 3. konsep ibadat
Bab 3. konsep ibadatBab 3. konsep ibadat
Bab 3. konsep ibadat
 
Cnc
CncCnc
Cnc
 
Chapter2
Chapter2Chapter2
Chapter2
 
Chapter1
Chapter1Chapter1
Chapter1
 
Chapter 7 automation techniques
Chapter 7  automation techniquesChapter 7  automation techniques
Chapter 7 automation techniques
 
Chapter 6 mfg systems
Chapter 6    mfg systemsChapter 6    mfg systems
Chapter 6 mfg systems
 
Chapter 3 automation devices
Chapter 3  automation devicesChapter 3  automation devices
Chapter 3 automation devices
 
Chapter 2 material handling
Chapter 2 material handlingChapter 2 material handling
Chapter 2 material handling
 
Chapter 1 introduction to automation
Chapter 1   introduction  to automationChapter 1   introduction  to automation
Chapter 1 introduction to automation
 

Ddpz2613 topic9 java

  • 1. HTML Concepts and Techniques Fifth Edition Chapter 9 Integrating JavaScript and HTML
  • 2. Chapter 9: Integrating JavaScript and HTML 2 Chapter Objectives • Understand the concept of JavaScript language. • Discuss how to integrate JavaScript and HTML • Insert <script> tags on a Web page • Define and describe JavaScript variables • Extract the current system date • Calculate the number of days from the current date to a future date
  • 3. Chapter 9: Integrating JavaScript and HTML 3 Chapter Objectives • Describe the write() method of the document object • Save the HTML file and test the Web page • Write a dynamic message to a Web page • Write a user-defined function that changes the color of the browser’s scroll bar
  • 4. Chapter 9: Integrating JavaScript and HTML 4 Chapter Objectives • Construct a URL from a select list option choice • Use the document’s location property to link to a new Web page • Use the lastModified property to display the last modified document date
  • 5. Chapter 9: Integrating JavaScript and HTML 5 Introduction • JavaScript is an event driven, object-based, programming language that provides various types of functionality to Web pages, such as the ability to interact with the user. • An event driven programming language is one that responds to events, such as user clicking a Submit or Calculate button. • JavaScript is object-based because it is a scripting language that uses built-in objects that belong to the browser. • An object is a person, place, or thing
  • 6. Built-in JavaScript Objects • Built-in object are values that are common to a browser (array, dates, strings etc.) and neither depend on nor belong to another object. • Table 9-1 contains a general list of the built-in JavaScript objects common to many browsers • JavaScript developers can create new objects based on the built-in objects and the new object inherit properties from the original objects. • JavaScript objects have properties and methods. Chapter 9: Integrating JavaScript and HTML 6
  • 7. Table 9-1 Built-in JavaScript Objects Object Description Array Return an ordered set of values Boolean Convert objects to Boolean values Date Accesses the system time and date Document Represent s the content of a browser’s window Form Represents forms created with the <form> tag Function Accesses information about specific functions History Keeps track of Web pages visited Image Represents images created with the <img> tag Location Switches to a new Web page Math Performs calculations Navigator Obtain information about the current Web browser Number Support special constants Screen Gives platform specific information about the user screen String Represents a set of character Windows and Frames Represent a browser windows or every frame within a browser windows Chapter 9: Integrating JavaScript and HTML 7
  • 8. Object and Property • Properties are attributes of objects and describe an object’s characteristics. • Table 9-2 shown an object and property are written by separating the object form its property with a period. • A specific value can be assigned to a property as shown in the following example: dog.breed=“terrier” where the dog is the object, breed is the property, and terrier is the value assigned to the property. Chapter 9: Integrating JavaScript and HTML 8
  • 9. Table 9-2 Object and Property General Form : object.property Comment : Where the object is stated first, then a period, then the descriptive property. A value can be assigned to the property, or the property can return a value as shown in the example below. Examples: document.bgColor=“lightblue” browser=navigator.appName Chapter 9: Integrating JavaScript and HTML 9
  • 10. Object and Method • Methods are actions that an object can perform • For example, methods associated with the dog object might be eat, fetch, and sit up. An object and one of its methods would be written as: dog.fetch() where the dog is the object and fetch is a method of the dog object • Methods are followed by parentheses which may be empty or may contain an argument. Chapter 9: Integrating JavaScript and HTML 10
  • 11. Object and Argument • An argument is a value given to a method. • Some methods require arguments, and others do not. • For example, given a dog object and fetch() method, a statement could be written as: dog.fetch(“ball”) where the argument “ball” describes what the dog fetches. • As shown in Table 9-3, the general form of writing an object with its method is similar to writing object and properties. Chapter 9: Integrating JavaScript and HTML 11
  • 12. Table 9-3 Object and Method General Form : objectname.method(argument value) Comment : Where objectname is the object, method is the action, and parameters are optional items or instructions should use. A period separates the object name from the property or method name Examples: document.write(“some text”) window.alert(“This is a message”) varToDayDate=Date.toString() Chapter 9: Integrating JavaScript and HTML 12
  • 13. User-Defined Functions • A user-defined function is JavaScript code written by developer to perform a particular task. • The function can be used whenever the task is needed, eliminating the need to repeat the code several times throughout an application. • JavaScript also contains a number of built-in functions called global functions such as: – close() – to close a window – open() – to open a window – print() – to print the contents of a windows • Most of these functions actually belong to the window object, but because the window object is assumed, they are called built-in functions Chapter 9: Integrating JavaScript and HTML 13
  • 14. • For a complete list of built-in functions, see the JavaScript Quick Reference in Appendix E. • Most JavaScript user-defined functions are called or activated using event-handler. • An event is the result of an action, such as mouse click or a document loading. • An event handler is JavaScript’s way to associate an action with a function. • In this project, you first write the functions, and then event handlers that will associate the functions with specific events, such as loading the Web page. Chapter 9: Integrating JavaScript and HTML 14
  • 15. Chapter 9: Integrating JavaScript and HTML 15 Opening an HTML File • Start Notepad, and, if necessary, maximize the window. Click Format on the menu bar. If the Word Wrap command does not have a check mark next to it, click Word Wrap • With a USB flash drive connected to one of the computer’s USB ports, click File on the menu bar and then click Open • If Computer is not displayed in the Favorite Links section, drag the top or bottom edge of the Open dialog box until Computer is displayed
  • 16. Chapter 9: Integrating JavaScript and HTML 16 Opening an HTML File • Click Computer in the Favorite Links section to display a list of available drives • If necessary, scroll until UDISK 2.0 (G:) appears in the list of available drives • Double-click USB drive (G:). Open the Chapter09 folder, and then double-click the ChapterFiles folder in the list of available folders • If necessary, click the Files of type box arrow, and then click All Files. Click chapter09.html in the list of files • Click the Open button in the Open dialog box to display the HTML code for the chapter09.html Web page
  • 17. Chapter 9: Integrating JavaScript and HTML 17 Opening an HTML File
  • 18. Chapter 9: Integrating JavaScript and HTML 18 Entering the Start <script> and Comment Tags • Click the blank line (line 32) press the spacebarto indent as shown below the <p style=“margin-left:10%”> tag • Type <script type="text/javascript"> as the beginning of the script and then press the ENTER key • Type <!--Hide from old browsers and then press the ENTER key
  • 19. Chapter 9: Integrating JavaScript and HTML 19 Entering the Start <script> and Comment Tags
  • 20. Chapter 9: Integrating JavaScript and HTML 20 Extracting the Current System Date Using the Date() Object • If necessary, click the chapter 09 - Notepad button on the taskbar to activate the Notepad window • Click line 41 below the <!--Hide from old browsers statement • Enter the JavaScript code shown in Table 9–13. Press ENTER at the end of each complete line of code. Enter the current year in the indexOf() method on line 48 • After typing the last line in Table 9–13, press the ENTER key once more to leave space for additional JavaScript code
  • 21. Chapter 9: Integrating JavaScript and HTML 21 Extracting the Current System Date Using the Date() Object
  • 22. Chapter 9: Integrating JavaScript and HTML 22 Creating a Date() Object Instance to Store a Future Date • Click line 51 • Substituting the current year for the spring date March 21, 2010, type var springDate = new Date("March 21, 2010) to set the date to the start of spring and then press the ENTER key
  • 23. Chapter 9: Integrating JavaScript and HTML 23 Calculating Milliseconds Between Two Dates Using the getTime() Method • Click line 52, if necessary • Type var daysToGo = springDate. getTime()-today. getTime() to calculate the number of milliseconds and then press the ENTER key
  • 24. Chapter 9: Integrating JavaScript and HTML 24 Converting Milliseconds to Days and Rounding Up Using the ceil() Method • Click line 53, if necessary • Type var daysToSpring = Math.ceil(daysTo Go/ (1000*60*60*24)) to convert milliseconds to days and then press the ENTER key twice
  • 25. Chapter 9: Integrating JavaScript and HTML 25 Writing Text and Variable Values to a Web Page • Click line 55, if necessary • Enter the JavaScript code shown in Table 9–16 to concatenate the message text with the stored values. Press the ENTER key only at the end of each complete line of code • Press the ENTER key an additional time after line 57
  • 26. Chapter 9: Integrating JavaScript and HTML 26 Writing Text and Variable Values to a Web Page
  • 27. Chapter 9: Integrating JavaScript and HTML 27 Entering the End Comment and </script> Tags • If necessary, click blank line 59 • Enter the following JavaScript code and do not press the ENTER key after the last line
  • 28. Chapter 9: Integrating JavaScript and HTML 28 Entering the End Comment and </script> Tags
  • 29. Chapter 9: Integrating JavaScript and HTML 29 Saving an HTML File • With a USB flash drive connected to one of the computer’s USB ports, click File on the Notepad menu bar and then click Save As. Type chapter09westlake.html in the File name text box (do not press the ENTER key) • If Computer is not displayed in the Favorite Links section, drag the top or bottom edge of the Save As dialog box until Computer is displayed • Click Computer in the Favorite Links section to display a list of available drives • If necessary, scroll until UDISK 2.0 (G:) appears in the list of available drives • If necessary, open the Chapter09ChapterFiles folder • Click the Save button in the Save As dialog box to save the file on the USB flash drive with the name chapter09westlake.html
  • 30. Chapter 9: Integrating JavaScript and HTML 30 Saving an HTML File
  • 31. Chapter 9: Integrating JavaScript and HTML 31 Testing the JavaScript on a Web Page • Click the Start button on the Windows Vista taskbar to display the Start menu • Click Internet Explorer (or another browser icon) on the Start menu. If necessary, click the Maximize button to maximize the browser window • Click the Address bar to select the URL on the Address bar • Type g:Chapter09ChapterFileschapter09westlake.html in the Address box. • Press ENTER to display the Web page
  • 32. Testing the JavaScript on a Web Page Chapter 9: Integrating JavaScript and HTML 32
  • 33. Chapter 9: Integrating JavaScript and HTML 33 Including the Date Last Modified in a Text String • If necessary, click the Notepad button on the taskbar to activate the Notepad window • Click line 91 below the second <p> </p> paragraph tag after the closing </table> tag • Enter the JavaScript code shown in Table 9–19. Press the ENTER key after each line but not after the last </script> line
  • 34. Chapter 9: Integrating JavaScript and HTML 34 Including the Date Last Modified in a Text String
  • 35. Chapter 9: Integrating JavaScript and HTML 35 Entering User-Defined Functions in the <head> Section • If necessary, click the chapter09westlake.html – Notepad icon on the taskbar • Click blank line 6 directly below the <title> tags • Enter the JavaScript code shown in Table 9–23 • Press the ENTER key twice after the last } to leave a blank line between user-defined functions
  • 36. Chapter 9: Integrating JavaScript and HTML 36 Entering User-Defined Functions in the <head> Section
  • 37. Entering the User-defined Function to Link to a new URL using the Drop-Down Menu List • Click line 14 if necessary • Enter the JavaScript code shown in Table 9–26 to enter the options and links for the drop-down menu list • Do not press the ENTER key after the last line Chapter 9: Integrating JavaScript and HTML 37
  • 38. Entering the User-defined Function to Link to a new URL using the Drop-Down Menu List Chapter 9: Integrating JavaScript and HTML 38
  • 39. Chapter 9: Integrating JavaScript and HTML 39 Associating a User-Defined Function with the onLoad Event • Click to the right of the y in the <body> tag in line 34 • Press the SPACEBAR once and then type onLoad=“scrollColor()” within the <body> tag. Do not press the ENTER key
  • 40. Chapter 9: Integrating JavaScript and HTML 40 Associating a User-Defined Function with the onLoad Event
  • 41. Chapter 9: Integrating JavaScript and HTML 41 Associating a User-Defined Function with the Select List • Click to the right of “Menu” in line 85 • Press the SPACEBAR once and then type onchange=“loadInfo(this.form)“ within the <select> tag. Do not press the ENTER key
  • 42. Chapter 9: Integrating JavaScript and HTML 42 Associating a User-Defined Function with the Select List
  • 43. Chapter 9: Integrating JavaScript and HTML 43 Saving an HTML File and Viewing and Testing the Completed Web Page • With the USB drive plugged into your computer, click File on the menu bar • Click Save on the File menu • Click the chapter 09WestLake Landscaping – Windows Internet Explorer button on the taskbar • Click the Refresh button on the Standard Buttons toolbar • Select Rocks and Stones in the dropdown menu list to display the Rocks and Stones page
  • 44. Chapter 9: Integrating JavaScript and HTML 44 Saving an HTML File and Viewing and Testing the Completed Web Page • Click the Back button on the Standard Buttons toolbar to return to the West Lake Landscaping page • Select Using Flowers in the drop-down menu list to display the Use of Flowers in Landscape Design page • Click the Home link at the bottom of the page to return to the West Lake Landscaping home page, and select Landscape Design Principles from the dropdown menu list to display the Design Principles page • Click the Home link at the bottom of the page to return to the West Lake Landscaping home page
  • 45. Saving an HTML File and Viewing and Testing the Completed Web Page Chapter 9: Integrating JavaScript and HTML 45
  • 46. Chapter 9: Integrating JavaScript and HTML 46 Validating a Web Page • Open Internet Explorer and navigate to the Web site validator.w3.org • Click the Validate by File Upload tab • Click the Browse button • Locate the chapter09westlake.html file on your storage device and click the file name • Click the Open button on the Choose file dialog box and the file name will be inserted into the File box • Click the Check button
  • 47. Chapter 9: Integrating JavaScript and HTML 47 Printing an HTML File • If necessary, click the chapter09westlake.html - Notepad button on the taskbar • Click File on the menu bar and then click Print. Click the Print button in the Print dialog box
  • 48. Chapter 9: Integrating JavaScript and HTML 48 Quitting Notepad and a Browser • Click the Close button on the browser title bar • Click the Close button on the Notepad window title bar
  • 49. Chapter 9: Integrating JavaScript and HTML 49 Chapter Summary • Discuss how to integrate JavaScript and HTML • Insert <script> tags on a Web page • Define and describe JavaScript variables • Extract the current system date • Calculate the number of days from the current date to a future date
  • 50. Chapter 9: Integrating JavaScript and HTML 50 Chapter Summary • Describe the write() method of the document object • Save the HTML file and test the Web page • Write a dynamic message to a Web page • Write a user-defined function that changes the color of the browser’s scroll bar
  • 51. Chapter 9: Integrating JavaScript and HTML 51 Chapter Summary • Construct a URL from a select list option choice • Use the document’s location property to link to a new Web page • Use the lastModified property to display the last modified document date
  • 52. HTML Concepts and Techniques Fifth Edition Chapter 9 Complete Integrating JavaScript and HTML