SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
CS 299 – Web Programming and Design
Overview of JavaScript and DOM
Instructor: Dr. Fang (Daisy) Tang
CS 299 – Web Programming and Design 2
Introduction to JavaScript
• What is JavaScript?
– It is designed to add interactivity to HTML pages
– It is a scripting language (a lightweight programming
language)
– It is an interpreted language (it executes without
preliminary compilation)
– Usually embedded directly into HTML pages
– And, Java and JavaScript are different
CS 299 – Web Programming and Design 3
What can a JavaScript Do?
• JavaScript gives HTML designers a programming tool:
– simple syntax
• JavaScript can put dynamic text into an HTML page
• JavaScript can react to events
• JavaScript can read and write HTML elements
• JavaScript can be used to validate data
• JavaScript can be used to detect the visitor’s browser
• JavaScript can be used to create cookies
– Store and retrieve information on the visitor’s computer
CS 299 – Web Programming and Design 4
JavaScript How To
• The HTML <script> tag is used to insert a JavaScript into an
HTML page
<script type=“text/javascript”>
document.write(“Hello World!”)
</script>
• Ending statements with a semicolon?
– Optional; required when you want to put multiple statements on a
single line
• JavaScript can be inserted within the head, the body, or use
external JavaScript file
• How to handle older browsers?
<script type=“text/javascript”>
<!—
document.write(“Hello World!”)
// -->
</script>
CS 299 – Web Programming and Design 5
JavaScript Where To
• You can include JavaScripts in head, body, or
simply use external JavaScript file (.js)
• JavaScripts in the body section will be
executed while the page loads
• JavaScripts in the head section will be
executed when called
• Examples:
– http://www.w3schools.com/js/js_whereto.asp
CS 299 – Web Programming and Design 6
JavaScript Basics
• Variables
• If … Else
• Switch
• Operators
• Popup Boxes
• Functions
• Loops (for, while)
• Events
• Try … Catch
• Throw
• onerror
• Special Text
• Guidelines
CS 299 – Web Programming and Design 7
Java Objects
• String
• Date
• Array
• Boolean
• Math
• RegExp
• HTML DOM
CS 299 – Web Programming and Design 8
RegExp: Regular Expression
• Two ways to define regular expression:
– new RegExp(“[xyz]”)
– or, /[xyz]/
• String object methods that supports regular
expressions:
– search: search a string for a specified value. Returns
the position of the value
– match: search a string for a specified value. Returns
an array of the found value(s)
– replace: replace characters with other characters
– split: split a string into an array of strings
CS 299 – Web Programming and Design 9
JavaScript Regular Expression Examples
• Check input for 5 digit number
– http://www.javascriptkit.com/javatutors/re.shtml
• Different categories of pattern matching:
– http://www.javascriptkit.com/javatutors/re2.shtml
CS 299 – Web Programming and Design 10
More RegExp Examples
• Example 1:
– var string1="Peter has 8 dollars and Jane has 15"
– parsestring1=string1.match(/d+/g)
– returns the array [8,15]
• Example 2:
– var string2="(304)434-5454"
– parsestring2=string2.replace(/[()-]/g, "")
– Returns "3044345454" (removes "(", ")", and "-")
• Example 3:
– var string3="1,2, 3, 4, 5"
– parsestring3=string3.split(/s*,s*/)
– Returns the array ["1","2","3","4","5"]
CS 299 – Web Programming and Design 11
More RegExp Examples
• Valid number: contains only an optional minus
sign, followed by digits, followed by an
optional dot (.) to signal decimals
• Valid date format
– 2-digit month, date separator, 2-digit day, date
separator, and a 4-digit year
– e.g., 02/02/2000, 02-02-2000, 02.02.2000
• http://www.javascriptkit.com/javatutors/re4.shtml
CS 299 – Web Programming and Design 12
HTML DOM
• What is the DOM?
– It stands for Document Object Model
– With JavaScript, we can restructure an entire HTML
document by adding, removing, changing, or
reordering items on a page
– JavaScript gains access to all HTML elements through
the DOM
CS 299 – Web Programming and Design 13
Using JavaScript Objects
• When you load a document in your web
browser, it creates a number of JavaScript
objects
• These objects exist in a hierarchy that reflects
the structure of the HTML page
CS 299 – Web Programming and Design 14
HTML DOM Structure
CS 299 – Web Programming and Design 15
DOM Resources
• Tutorials:
– http://www.w3schools.com/htmldom/default.asp
• DOM examples:
– http://www.w3schools.com/htmldom/dom_examples.asp
CS 299 – Web Programming and Design 16
Java Advanced
• Browser
• Cookies
• Validation
• Animation
• Timing
• Create your own object
CS 299 – Web Programming and Design 17
Some Dynamic HTML Examples
• http://www.w3schools.com/dhtml/dhtml_examples.asp
CS 299 – Web Programming and Design 18
Case Study
• More Examples:
– http://www.pages.org/javascript/index.html
– http://www.csupomona.edu/~ftang/www/courses/C
S299-S09/examples/changestyle.html
• Form validation:
– http://www.xs4all.nl/~sbpoley/webmatters/formval.html

More Related Content

PPT
Javascript
ODP
Introduction of Html/css/js
PPTX
Lab #2: Introduction to Javascript
PPT
Introduction to JavaScript (1).ppt
PPT
Html Ppt
PPTX
Angular overview
PDF
Basics of JavaScript
PPTX
Routing ppt
Javascript
Introduction of Html/css/js
Lab #2: Introduction to Javascript
Introduction to JavaScript (1).ppt
Html Ppt
Angular overview
Basics of JavaScript
Routing ppt

What's hot (20)

PDF
PDF
jQuery for beginners
PPTX
Event In JavaScript
PPT
Js ppt
PPTX
Java script
PPTX
Complete Lecture on Css presentation
PDF
Bootstrap
PPT
Javascript
PPTX
PDF
JavaScript - Chapter 12 - Document Object Model
PPTX
Bootstrap 3
PPTX
PPT
CSS Basics
PPTX
Javascript 101
PPTX
Flexbox
PPTX
Java script
PPT
Ppt of web development
PPTX
Cascading Style Sheet (CSS)
PPT
Introduction to JavaScript
jQuery for beginners
Event In JavaScript
Js ppt
Java script
Complete Lecture on Css presentation
Bootstrap
Javascript
JavaScript - Chapter 12 - Document Object Model
Bootstrap 3
CSS Basics
Javascript 101
Flexbox
Java script
Ppt of web development
Cascading Style Sheet (CSS)
Introduction to JavaScript
Ad

Similar to javaScript.ppt (20)

PDF
GDG-USAR Tech winter break 2024 USAR.pdf
PDF
Java script
PPTX
PPTX
JS Essence
PPTX
SPSTC - SharePoint & jQuery Essentials
PPT
lecture 6 javascript event and event handling.ppt
PDF
Intro JavaScript
PPTX
SharePoint and jQuery Essentials
PDF
javascriptPresentation.pdf
PPTX
Lecture 5 javascript
PPTX
JavaScripts & jQuery
PPTX
Future-proof Development for Classic SharePoint
PPTX
BrazilJS Perf Doctor Talk
PPT
Presentation JavaScript Introduction Data Types Variables Control Structure
PPTX
Getting Started with Javascript
PDF
SQL Server Managing Test Data & Stress Testing January 2011
PDF
Mongo db eveningschemadesign
PDF
Java Script
PPT
Java Script
PPT
JavaScript ppt for introduction of javascripta
GDG-USAR Tech winter break 2024 USAR.pdf
Java script
JS Essence
SPSTC - SharePoint & jQuery Essentials
lecture 6 javascript event and event handling.ppt
Intro JavaScript
SharePoint and jQuery Essentials
javascriptPresentation.pdf
Lecture 5 javascript
JavaScripts & jQuery
Future-proof Development for Classic SharePoint
BrazilJS Perf Doctor Talk
Presentation JavaScript Introduction Data Types Variables Control Structure
Getting Started with Javascript
SQL Server Managing Test Data & Stress Testing January 2011
Mongo db eveningschemadesign
Java Script
Java Script
JavaScript ppt for introduction of javascripta
Ad

Recently uploaded (20)

PDF
Laughter Yoga Basic Learning Workshop Manual
PPTX
Lecture (1)-Introduction.pptx business communication
PDF
Digital Marketing & E-commerce Certificate Glossary.pdf.................
DOCX
Business Management - unit 1 and 2
PDF
Ôn tập tiếng anh trong kinh doanh nâng cao
PDF
Roadmap Map-digital Banking feature MB,IB,AB
PDF
Elevate Cleaning Efficiency Using Tallfly Hair Remover Roller Factory Expertise
PPT
Lecture 3344;;,,(,(((((((((((((((((((((((
PDF
Chapter 5_Foreign Exchange Market in .pdf
PDF
How to Get Funding for Your Trucking Business
PDF
Cours de Système d'information about ERP.pdf
PDF
NewBase 12 August 2025 Energy News issue - 1812 by Khaled Al Awadi_compresse...
PDF
Solara Labs: Empowering Health through Innovative Nutraceutical Solutions
PDF
COST SHEET- Tender and Quotation unit 2.pdf
PPTX
Principles of Marketing, Industrial, Consumers,
PDF
Power and position in leadershipDOC-20250808-WA0011..pdf
PPTX
HR Introduction Slide (1).pptx on hr intro
PDF
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
PPTX
Board-Reporting-Package-by-Umbrex-5-23-23.pptx
PPTX
job Avenue by vinith.pptxvnbvnvnvbnvbnbmnbmbh
Laughter Yoga Basic Learning Workshop Manual
Lecture (1)-Introduction.pptx business communication
Digital Marketing & E-commerce Certificate Glossary.pdf.................
Business Management - unit 1 and 2
Ôn tập tiếng anh trong kinh doanh nâng cao
Roadmap Map-digital Banking feature MB,IB,AB
Elevate Cleaning Efficiency Using Tallfly Hair Remover Roller Factory Expertise
Lecture 3344;;,,(,(((((((((((((((((((((((
Chapter 5_Foreign Exchange Market in .pdf
How to Get Funding for Your Trucking Business
Cours de Système d'information about ERP.pdf
NewBase 12 August 2025 Energy News issue - 1812 by Khaled Al Awadi_compresse...
Solara Labs: Empowering Health through Innovative Nutraceutical Solutions
COST SHEET- Tender and Quotation unit 2.pdf
Principles of Marketing, Industrial, Consumers,
Power and position in leadershipDOC-20250808-WA0011..pdf
HR Introduction Slide (1).pptx on hr intro
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
Board-Reporting-Package-by-Umbrex-5-23-23.pptx
job Avenue by vinith.pptxvnbvnvnvbnvbnbmnbmbh

javaScript.ppt

  • 1. CS 299 – Web Programming and Design Overview of JavaScript and DOM Instructor: Dr. Fang (Daisy) Tang
  • 2. CS 299 – Web Programming and Design 2 Introduction to JavaScript • What is JavaScript? – It is designed to add interactivity to HTML pages – It is a scripting language (a lightweight programming language) – It is an interpreted language (it executes without preliminary compilation) – Usually embedded directly into HTML pages – And, Java and JavaScript are different
  • 3. CS 299 – Web Programming and Design 3 What can a JavaScript Do? • JavaScript gives HTML designers a programming tool: – simple syntax • JavaScript can put dynamic text into an HTML page • JavaScript can react to events • JavaScript can read and write HTML elements • JavaScript can be used to validate data • JavaScript can be used to detect the visitor’s browser • JavaScript can be used to create cookies – Store and retrieve information on the visitor’s computer
  • 4. CS 299 – Web Programming and Design 4 JavaScript How To • The HTML <script> tag is used to insert a JavaScript into an HTML page <script type=“text/javascript”> document.write(“Hello World!”) </script> • Ending statements with a semicolon? – Optional; required when you want to put multiple statements on a single line • JavaScript can be inserted within the head, the body, or use external JavaScript file • How to handle older browsers? <script type=“text/javascript”> <!— document.write(“Hello World!”) // --> </script>
  • 5. CS 299 – Web Programming and Design 5 JavaScript Where To • You can include JavaScripts in head, body, or simply use external JavaScript file (.js) • JavaScripts in the body section will be executed while the page loads • JavaScripts in the head section will be executed when called • Examples: – http://www.w3schools.com/js/js_whereto.asp
  • 6. CS 299 – Web Programming and Design 6 JavaScript Basics • Variables • If … Else • Switch • Operators • Popup Boxes • Functions • Loops (for, while) • Events • Try … Catch • Throw • onerror • Special Text • Guidelines
  • 7. CS 299 – Web Programming and Design 7 Java Objects • String • Date • Array • Boolean • Math • RegExp • HTML DOM
  • 8. CS 299 – Web Programming and Design 8 RegExp: Regular Expression • Two ways to define regular expression: – new RegExp(“[xyz]”) – or, /[xyz]/ • String object methods that supports regular expressions: – search: search a string for a specified value. Returns the position of the value – match: search a string for a specified value. Returns an array of the found value(s) – replace: replace characters with other characters – split: split a string into an array of strings
  • 9. CS 299 – Web Programming and Design 9 JavaScript Regular Expression Examples • Check input for 5 digit number – http://www.javascriptkit.com/javatutors/re.shtml • Different categories of pattern matching: – http://www.javascriptkit.com/javatutors/re2.shtml
  • 10. CS 299 – Web Programming and Design 10 More RegExp Examples • Example 1: – var string1="Peter has 8 dollars and Jane has 15" – parsestring1=string1.match(/d+/g) – returns the array [8,15] • Example 2: – var string2="(304)434-5454" – parsestring2=string2.replace(/[()-]/g, "") – Returns "3044345454" (removes "(", ")", and "-") • Example 3: – var string3="1,2, 3, 4, 5" – parsestring3=string3.split(/s*,s*/) – Returns the array ["1","2","3","4","5"]
  • 11. CS 299 – Web Programming and Design 11 More RegExp Examples • Valid number: contains only an optional minus sign, followed by digits, followed by an optional dot (.) to signal decimals • Valid date format – 2-digit month, date separator, 2-digit day, date separator, and a 4-digit year – e.g., 02/02/2000, 02-02-2000, 02.02.2000 • http://www.javascriptkit.com/javatutors/re4.shtml
  • 12. CS 299 – Web Programming and Design 12 HTML DOM • What is the DOM? – It stands for Document Object Model – With JavaScript, we can restructure an entire HTML document by adding, removing, changing, or reordering items on a page – JavaScript gains access to all HTML elements through the DOM
  • 13. CS 299 – Web Programming and Design 13 Using JavaScript Objects • When you load a document in your web browser, it creates a number of JavaScript objects • These objects exist in a hierarchy that reflects the structure of the HTML page
  • 14. CS 299 – Web Programming and Design 14 HTML DOM Structure
  • 15. CS 299 – Web Programming and Design 15 DOM Resources • Tutorials: – http://www.w3schools.com/htmldom/default.asp • DOM examples: – http://www.w3schools.com/htmldom/dom_examples.asp
  • 16. CS 299 – Web Programming and Design 16 Java Advanced • Browser • Cookies • Validation • Animation • Timing • Create your own object
  • 17. CS 299 – Web Programming and Design 17 Some Dynamic HTML Examples • http://www.w3schools.com/dhtml/dhtml_examples.asp
  • 18. CS 299 – Web Programming and Design 18 Case Study • More Examples: – http://www.pages.org/javascript/index.html – http://www.csupomona.edu/~ftang/www/courses/C S299-S09/examples/changestyle.html • Form validation: – http://www.xs4all.nl/~sbpoley/webmatters/formval.html