SlideShare a Scribd company logo
Copyright © Terry Felke-Morris
WEB DEVELOPMENT & DESIGN
FOUNDATIONS WITH HTML5
Chapter 14
Key Concepts
1Copyright © Terry Felke-Morris
Copyright © Terry Felke-Morris
LEARNING OUTCOMES
 In this chapter, you will learn how to:
 Describe common uses of JavaScript in web pages.
 Describe the purpose of the Document Object Model
and list some common events.
 Create a simple JavaScript using the script element and
the alert() method.
 Use variables, operators and the if control structure.
 Create a basic form validation script.
2
Copyright © Terry Felke-Morris
WHAT IS JAVASCRIPT?
 Object-based scripting language
 Works with the objects associated with a
Wwb page document
 the window
 the document
 the elements
 such as forms, images, hyperlinks, etc
3
Copyright © Terry Felke-Morris
WHAT IS JAVASCRIPT?
 Originally developed by Netscape
 Named LiveScript
 Netscape & Sun Microsystems Collaboration
 LiveScript renamed JavaScript
 JavaScript is NOT Java
4
Copyright © Terry Felke-Morris
COMMON USES OF JAVASCRIPT
 Display a message box
 Select list navigation
 Edit and validate form information
 Create a new window with a specified size and
screen position
 Image Rollovers
 Status Messages
 Display Current Date
 Calculations
5
Copyright © Terry Felke-Morris
CODING JAVASCRIPT
 JavaScript statements can be coded on a web page
using two different techniques:
 Place JavaScript code between <script> tags
 Place JavaScript code as part of an event attached to an
HTML element
6
Copyright © Terry Felke-Morris
JAVASCRIPT: USING THE SCRIPT ELEMENT
The script element
◦ A container tag
◦ May be placed in either the head or the body
section of a web page
<script type="text/javascript">
<!- -
alert("Welcome to Our Site");
// - ->
</script>
7
Copyright © Terry Felke-Morris
CHECKPOINT
1. Describe at least three popular uses for
JavaScript.
2. How many JavaScript code blocks can be
embedded in an HTML document?
3. Describe a method that can be used to find an
error in a JavaScript code block.
8
Copyright © Terry Felke-Morris
DOCUMENT OBJECT MODEL (DOM)
A portion of the
DOM is shown at the
left.
Defines every object
and element on a web
page
Hierarchical structure
Accesses page
elements and apply
styles to page
elements
9
Copyright © Terry Felke-Morris
OBJECT
 An object is a thing or entity.
 Browser window
 Submit button
 Web page document
10
Copyright © Terry Felke-Morris
PROPERTY
 A property is a characteristic or attribute of an
object.
 The background color of a web page document
document.bgcolor
 The date the web page file was last modified
document.lastmodified
 The src file of an image object
image1.src
11
Copyright © Terry Felke-Morris
METHOD
 A method is an action (a verb)
 Writing text to a web page document
document.write()
 Submitting a form
form1.submit()
12
Copyright © Terry Felke-Morris
JAVASCRIPT AND EVENTS
Events:
actions taken by the web page visitor
◦ clicking (onclick),
◦ placing the mouse on an element (onmouseover),
◦ removing the mouse from an element (onmouseout),
◦ loading the page (onload),
◦ unloading the page (onunload), etc.
13
EVENTS
Event Event Handler
click onclick
load onload
mouseover onmouseover
mouseout onmouseout
submit onsubmit
unload onunload
14
Copyright © Terry Felke-Morris
JAVASCRIPT AND EVENTS
 JavaScript can be configured to perform actions when
events occur.
 The event name is coded as an attribute of an HTML tag
 The value of the event attribute contains the JavaScript code
Example:
Display an alert box when the mouse is placed over a
hyperlink.
15
<a href="home.htm" onmouseover="alert('Click to go home')">Home</a>
Copyright © Terry Felke-Morris
JAVASCRIPT DEBUGGING(1)
Check the syntax of the statements
◦ Pay very close attention to upper and lower case letters, spaces, and quotations
Verify that you have saved the page with your most recent changes
Verify that you are testing the most recent version of the page
(refresh or reload the page)
If you get an error message, use the error messages that are
displayed by the browser
◦ In Firefox: Select Tools > Error Console
16
Copyright © Terry Felke-Morris
JAVASCRIPT DEBUGGING(2)
 Use the Firefox browser:
 Select Tools > Error Console from the Menu
 The Error Console will indicate an issue and the line number
 This may not be exactly where the problem is
 Sometimes the error is a one or two lines above the indicated line
number.
17
Copyright © Terry Felke-Morris
CHECKPOINT
1. With respect to objects, describe the difference between a
property and a method. Feel free to use words like “thing,”
“action,”“description,”“attribute,” and so forth.
2. What is the difference between an event and an event
handler?
3. Where are event handlers placed in the HTML document?
18
Copyright © Terry Felke-Morris
VARIABLE
 A variable is a placeholder for information.
 The variable is stored in the computer’s memory
(RAM).
var userName;
userName = "Karen";
document.write(userName);
19
Copyright © Terry Felke-Morris
PROMPTS
 prompt() method
 Displays a message and accepts a value from the user
myName = prompt(“prompt message”);
 The value typed by the user is stored in the variable
myName
20
ARITHMETIC OPERATORS
Operat
or
Description Example Value of
Quantity
= assign quantity = 10 10
+ addition quantity = 10 + 6 16
- subtraction quantity = 10 - 6 4
* multiplication quantity = 10 * 2 20
/ division quantity = 10 / 2 5
21
COMPARISON OPERATORS
Operator Description Example Sample values of quantity
that would result in true
= = Double equals
sign
(equivalent)
“is exactly
equal to”
quantity = = 10 10
> Greater than quantity > 10 11, 12 (but not 10)
> = Greater than
or equal to
quantity > = 10 10, 11, 12
< Less than quantity < 10 8, 9 (but not 10)
< = Less than or
equal to
quantity < = 10 8, 9, 10
! = Not equal to quantity ! = 10 8, 9, 11 (but not 10)
22
Copyright © Terry Felke-Morris
DECISION MAKING
if (condition) {
… commands to execute if condition is true
}
else {
… commands to execute if condition is false
}
23
Copyright © Terry Felke-Morris
FUNCTION
 A function is a block of one or more JavaScript
statements with a specific purpose, which can be
run when needed.
function function_name() {
... JavaScript statements …
}
24
Copyright © Terry Felke-Morris
USING FUNCTIONS
function showAlert() {
alert("Please click OK to continue.");
}
25
Calling the Function
showAlert();
Defining the Function
Copyright © Terry Felke-Morris
CHECKPOINT
1. Describe a method that can be used to gather a piece of data such as
the user’s age.
2. Write the JavaScript code to display an alert message for users who
are under 18 years old and a different alert message for users who
are 18 years or older.
3. What is a function definition?
26
Copyright © Terry Felke-Morris
FORMVALIDATION
 It is common to use JavaScript to validate form
information before submitting it to the web server.
 Is the name entered?
 Is the e-mail address of correct format?
 Is the phone number in the correct format?
 See Hands-on Practice 14.8
27
Copyright © Terry Felke-Morris
VALIDATING FORM FIELDS
 Use the "" or null to check to determine if a
form field has information
if (document.forms[0].userName.value == "" ) {
alert("Name field cannot be empty.");
return false;
} // end if
28
Copyright © Terry Felke-Morris
JAVASCRIPT & ACCESSIBILITY
 Don’t expect JavaScript to always function for
every visitor
 Some may have JavaScript disabled
 Some may be physically unable to click a mouse
 Provide a way for your site to be used if JavaScript
is not functioning
 Plain text links
 E-mail contact info
29
Copyright © Terry Felke-Morris
CHECKPOINT
1. What is meant by the term “form data validation”?
2. Give three examples of form data that may require
validation.
3. Should you always expect your JavaScript to “work” –
why or why not?
30
Copyright © Terry Felke-Morris
SUMMARY
This chapter introduced the use of JavaScript on
web pages.
Topics included:
 Common uses of JavaScript in web pages.
 The purpose of the Document Object Model
 The script element
 The alert() method
 Use variables, operators and the if control structure.
 Configure functions
 Using JavaScript to validate a form
31

More Related Content

PPT
Chapter 13 - Web Design
PPT
Chapter 10 - Web Design
PPT
Chapter 7 - Web Design
PPT
Chapter 9 - Web Design
PPT
Chapter7
PPT
Chapter2
PPT
Chapter13
PPT
Chapter14
Chapter 13 - Web Design
Chapter 10 - Web Design
Chapter 7 - Web Design
Chapter 9 - Web Design
Chapter7
Chapter2
Chapter13
Chapter14

What's hot (20)

PPT
Chapter11
PPT
Chapter10
PPT
Chapter5
PPT
Chapter1
PPT
Chapter3
PPT
How websites and search engines work
PPT
Chapter4
PDF
Basics of css and xhtml
PPTX
WordPress HTML, CSS & Child Themes
KEY
An Introduction to HTML5
DOCX
Posterous Guide: The Easy Way to Blog
PPTX
APEX navigation concepts
PPT
Introduction to HTML5
PDF
Intro to html 5
PDF
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
PPT
Blog It Up, Baby! Extending the new IBM Lotus Domino Blog Template
PDF
IBM Connections mail with exchange backend
PPT
Internet Librarian Slides
PPTX
Intro to ExpressionEngine and CodeIgniter
PPTX
Html5 tutorial for beginners
Chapter11
Chapter10
Chapter5
Chapter1
Chapter3
How websites and search engines work
Chapter4
Basics of css and xhtml
WordPress HTML, CSS & Child Themes
An Introduction to HTML5
Posterous Guide: The Easy Way to Blog
APEX navigation concepts
Introduction to HTML5
Intro to html 5
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Blog It Up, Baby! Extending the new IBM Lotus Domino Blog Template
IBM Connections mail with exchange backend
Internet Librarian Slides
Intro to ExpressionEngine and CodeIgniter
Html5 tutorial for beginners
Ad

Similar to Chapter 14 - Web Design (20)

PPTX
unit4 wp.pptxjvlbpuvghuigv8ytg2ugvugvuygv
PPTX
Javascript
PPT
PDF
JavaScript
PDF
JavaScript
PPT
Java script
PDF
Iwt note(module 2)
PPT
Javascript sivasoft
PPTX
JavaScript lesson 1.pptx
PPTX
Java Script basics and DOM
PPTX
javaScript and jQuery
PDF
8.-Javascript-report powerpoint presentation
PPT
Javascript1
PDF
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
PPT
13665449.ppt
PPT
JavaScript Tutorial
PPT
JavaScript Misunderstood
PPTX
Java script basics
PPSX
Javascript variables and datatypes
unit4 wp.pptxjvlbpuvghuigv8ytg2ugvugvuygv
Javascript
JavaScript
JavaScript
Java script
Iwt note(module 2)
Javascript sivasoft
JavaScript lesson 1.pptx
Java Script basics and DOM
javaScript and jQuery
8.-Javascript-report powerpoint presentation
Javascript1
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
13665449.ppt
JavaScript Tutorial
JavaScript Misunderstood
Java script basics
Javascript variables and datatypes
Ad

More from tclanton4 (20)

PPT
Chapter 12 - Web Design
PPT
Chapter 11 - Web Design
PPT
Chapter 8 - Web Design
PPT
Chapter 6 - Web Design
PPT
Chapter 5 - Web Design
PPT
Chapter 4 - Web Design
PPT
Chapter 3 - Web Design
PPT
Chapter 1 - Web Design
PPTX
Base2
PPTX
Base1
PPTX
Impress
PPTX
Project Mgt
PPTX
Charts in Calc
PPTX
Formatting a Worksheet in Calc
PPTX
Creating a Worksheet in Calc
PPTX
Advanced Features of Writer
PPTX
Creating a Writer Document
PPTX
Formatting Features of Writer
PPTX
Getting Started - The Basics
PPT
Intro to Information Systems
Chapter 12 - Web Design
Chapter 11 - Web Design
Chapter 8 - Web Design
Chapter 6 - Web Design
Chapter 5 - Web Design
Chapter 4 - Web Design
Chapter 3 - Web Design
Chapter 1 - Web Design
Base2
Base1
Impress
Project Mgt
Charts in Calc
Formatting a Worksheet in Calc
Creating a Worksheet in Calc
Advanced Features of Writer
Creating a Writer Document
Formatting Features of Writer
Getting Started - The Basics
Intro to Information Systems

Recently uploaded (20)

PDF
Computing-Curriculum for Schools in Ghana
PPTX
Cell Types and Its function , kingdom of life
PDF
Yogi Goddess Pres Conference Studio Updates
PPTX
master seminar digital applications in india
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Trump Administration's workforce development strategy
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
History, Philosophy and sociology of education (1).pptx
Computing-Curriculum for Schools in Ghana
Cell Types and Its function , kingdom of life
Yogi Goddess Pres Conference Studio Updates
master seminar digital applications in india
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Final Presentation General Medicine 03-08-2024.pptx
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Supply Chain Operations Speaking Notes -ICLT Program
Paper A Mock Exam 9_ Attempt review.pdf.
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Microbial disease of the cardiovascular and lymphatic systems
Trump Administration's workforce development strategy
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
History, Philosophy and sociology of education (1).pptx

Chapter 14 - Web Design

  • 1. Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 Chapter 14 Key Concepts 1Copyright © Terry Felke-Morris
  • 2. Copyright © Terry Felke-Morris LEARNING OUTCOMES  In this chapter, you will learn how to:  Describe common uses of JavaScript in web pages.  Describe the purpose of the Document Object Model and list some common events.  Create a simple JavaScript using the script element and the alert() method.  Use variables, operators and the if control structure.  Create a basic form validation script. 2
  • 3. Copyright © Terry Felke-Morris WHAT IS JAVASCRIPT?  Object-based scripting language  Works with the objects associated with a Wwb page document  the window  the document  the elements  such as forms, images, hyperlinks, etc 3
  • 4. Copyright © Terry Felke-Morris WHAT IS JAVASCRIPT?  Originally developed by Netscape  Named LiveScript  Netscape & Sun Microsystems Collaboration  LiveScript renamed JavaScript  JavaScript is NOT Java 4
  • 5. Copyright © Terry Felke-Morris COMMON USES OF JAVASCRIPT  Display a message box  Select list navigation  Edit and validate form information  Create a new window with a specified size and screen position  Image Rollovers  Status Messages  Display Current Date  Calculations 5
  • 6. Copyright © Terry Felke-Morris CODING JAVASCRIPT  JavaScript statements can be coded on a web page using two different techniques:  Place JavaScript code between <script> tags  Place JavaScript code as part of an event attached to an HTML element 6
  • 7. Copyright © Terry Felke-Morris JAVASCRIPT: USING THE SCRIPT ELEMENT The script element ◦ A container tag ◦ May be placed in either the head or the body section of a web page <script type="text/javascript"> <!- - alert("Welcome to Our Site"); // - -> </script> 7
  • 8. Copyright © Terry Felke-Morris CHECKPOINT 1. Describe at least three popular uses for JavaScript. 2. How many JavaScript code blocks can be embedded in an HTML document? 3. Describe a method that can be used to find an error in a JavaScript code block. 8
  • 9. Copyright © Terry Felke-Morris DOCUMENT OBJECT MODEL (DOM) A portion of the DOM is shown at the left. Defines every object and element on a web page Hierarchical structure Accesses page elements and apply styles to page elements 9
  • 10. Copyright © Terry Felke-Morris OBJECT  An object is a thing or entity.  Browser window  Submit button  Web page document 10
  • 11. Copyright © Terry Felke-Morris PROPERTY  A property is a characteristic or attribute of an object.  The background color of a web page document document.bgcolor  The date the web page file was last modified document.lastmodified  The src file of an image object image1.src 11
  • 12. Copyright © Terry Felke-Morris METHOD  A method is an action (a verb)  Writing text to a web page document document.write()  Submitting a form form1.submit() 12
  • 13. Copyright © Terry Felke-Morris JAVASCRIPT AND EVENTS Events: actions taken by the web page visitor ◦ clicking (onclick), ◦ placing the mouse on an element (onmouseover), ◦ removing the mouse from an element (onmouseout), ◦ loading the page (onload), ◦ unloading the page (onunload), etc. 13
  • 14. EVENTS Event Event Handler click onclick load onload mouseover onmouseover mouseout onmouseout submit onsubmit unload onunload 14
  • 15. Copyright © Terry Felke-Morris JAVASCRIPT AND EVENTS  JavaScript can be configured to perform actions when events occur.  The event name is coded as an attribute of an HTML tag  The value of the event attribute contains the JavaScript code Example: Display an alert box when the mouse is placed over a hyperlink. 15 <a href="home.htm" onmouseover="alert('Click to go home')">Home</a>
  • 16. Copyright © Terry Felke-Morris JAVASCRIPT DEBUGGING(1) Check the syntax of the statements ◦ Pay very close attention to upper and lower case letters, spaces, and quotations Verify that you have saved the page with your most recent changes Verify that you are testing the most recent version of the page (refresh or reload the page) If you get an error message, use the error messages that are displayed by the browser ◦ In Firefox: Select Tools > Error Console 16
  • 17. Copyright © Terry Felke-Morris JAVASCRIPT DEBUGGING(2)  Use the Firefox browser:  Select Tools > Error Console from the Menu  The Error Console will indicate an issue and the line number  This may not be exactly where the problem is  Sometimes the error is a one or two lines above the indicated line number. 17
  • 18. Copyright © Terry Felke-Morris CHECKPOINT 1. With respect to objects, describe the difference between a property and a method. Feel free to use words like “thing,” “action,”“description,”“attribute,” and so forth. 2. What is the difference between an event and an event handler? 3. Where are event handlers placed in the HTML document? 18
  • 19. Copyright © Terry Felke-Morris VARIABLE  A variable is a placeholder for information.  The variable is stored in the computer’s memory (RAM). var userName; userName = "Karen"; document.write(userName); 19
  • 20. Copyright © Terry Felke-Morris PROMPTS  prompt() method  Displays a message and accepts a value from the user myName = prompt(“prompt message”);  The value typed by the user is stored in the variable myName 20
  • 21. ARITHMETIC OPERATORS Operat or Description Example Value of Quantity = assign quantity = 10 10 + addition quantity = 10 + 6 16 - subtraction quantity = 10 - 6 4 * multiplication quantity = 10 * 2 20 / division quantity = 10 / 2 5 21
  • 22. COMPARISON OPERATORS Operator Description Example Sample values of quantity that would result in true = = Double equals sign (equivalent) “is exactly equal to” quantity = = 10 10 > Greater than quantity > 10 11, 12 (but not 10) > = Greater than or equal to quantity > = 10 10, 11, 12 < Less than quantity < 10 8, 9 (but not 10) < = Less than or equal to quantity < = 10 8, 9, 10 ! = Not equal to quantity ! = 10 8, 9, 11 (but not 10) 22
  • 23. Copyright © Terry Felke-Morris DECISION MAKING if (condition) { … commands to execute if condition is true } else { … commands to execute if condition is false } 23
  • 24. Copyright © Terry Felke-Morris FUNCTION  A function is a block of one or more JavaScript statements with a specific purpose, which can be run when needed. function function_name() { ... JavaScript statements … } 24
  • 25. Copyright © Terry Felke-Morris USING FUNCTIONS function showAlert() { alert("Please click OK to continue."); } 25 Calling the Function showAlert(); Defining the Function
  • 26. Copyright © Terry Felke-Morris CHECKPOINT 1. Describe a method that can be used to gather a piece of data such as the user’s age. 2. Write the JavaScript code to display an alert message for users who are under 18 years old and a different alert message for users who are 18 years or older. 3. What is a function definition? 26
  • 27. Copyright © Terry Felke-Morris FORMVALIDATION  It is common to use JavaScript to validate form information before submitting it to the web server.  Is the name entered?  Is the e-mail address of correct format?  Is the phone number in the correct format?  See Hands-on Practice 14.8 27
  • 28. Copyright © Terry Felke-Morris VALIDATING FORM FIELDS  Use the "" or null to check to determine if a form field has information if (document.forms[0].userName.value == "" ) { alert("Name field cannot be empty."); return false; } // end if 28
  • 29. Copyright © Terry Felke-Morris JAVASCRIPT & ACCESSIBILITY  Don’t expect JavaScript to always function for every visitor  Some may have JavaScript disabled  Some may be physically unable to click a mouse  Provide a way for your site to be used if JavaScript is not functioning  Plain text links  E-mail contact info 29
  • 30. Copyright © Terry Felke-Morris CHECKPOINT 1. What is meant by the term “form data validation”? 2. Give three examples of form data that may require validation. 3. Should you always expect your JavaScript to “work” – why or why not? 30
  • 31. Copyright © Terry Felke-Morris SUMMARY This chapter introduced the use of JavaScript on web pages. Topics included:  Common uses of JavaScript in web pages.  The purpose of the Document Object Model  The script element  The alert() method  Use variables, operators and the if control structure.  Configure functions  Using JavaScript to validate a form 31