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

What's hot (20)

PDF
Html frames
eShikshak
 
PPTX
Event In JavaScript
ShahDhruv21
 
PPTX
Java script
reddivarihareesh
 
PPT
Introduction to JavaScript
Andres Baravalle
 
PDF
Javascript essentials
Bedis ElAchèche
 
PDF
jQuery for beginners
Arulmurugan Rajaraman
 
PPTX
Static and Dynamic webpage
Aishwarya Pallai
 
PPT
Introduction to JavaScript (1).ppt
MuhammadRehan856177
 
PDF
JavaScript Programming
Sehwan Noh
 
PPTX
Java script
Shyam Khant
 
PDF
HTML CSS Basics
Mai Moustafa
 
PPT
JavaScript Tutorial
Bui Kiet
 
PDF
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
PPTX
HTML Forms
Ravinder Kamboj
 
PPT
Css Ppt
Hema Prasanth
 
PPTX
Javascript operators
Mohit Rana
 
PDF
JavaScript - Chapter 3 - Introduction
WebStackAcademy
 
PPTX
Html ppt
santosh lamba
 
PPTX
Java Server Pages(jsp)
Manisha Keim
 
Html frames
eShikshak
 
Event In JavaScript
ShahDhruv21
 
Java script
reddivarihareesh
 
Introduction to JavaScript
Andres Baravalle
 
Javascript essentials
Bedis ElAchèche
 
jQuery for beginners
Arulmurugan Rajaraman
 
Static and Dynamic webpage
Aishwarya Pallai
 
Introduction to JavaScript (1).ppt
MuhammadRehan856177
 
JavaScript Programming
Sehwan Noh
 
Java script
Shyam Khant
 
HTML CSS Basics
Mai Moustafa
 
JavaScript Tutorial
Bui Kiet
 
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
HTML Forms
Ravinder Kamboj
 
Css Ppt
Hema Prasanth
 
Javascript operators
Mohit Rana
 
JavaScript - Chapter 3 - Introduction
WebStackAcademy
 
Html ppt
santosh lamba
 
Java Server Pages(jsp)
Manisha Keim
 

Similar to javaScript.ppt (20)

PDF
Java script
Sanjay Gunjal
 
PDF
Introduction to web programming with JavaScript
T11 Sessions
 
PPTX
Web technologies-course 07.pptx
Stefan Oprea
 
PPTX
JavaScript_III.pptx
rashmiisrani1
 
PPTX
JavascriptCOmpleteGuideCourseFromZero.pptx
AlaeddineTheljani
 
PPTX
Monster JavaScript Course - 50+ projects and applications
Laurence Svekis ✔
 
PPT
Html JavaScript and CSS
Radhe Krishna Rajan
 
PPTX
MYSQL DATABASE INTRODUCTION TO JAVASCRIPT.pptx
ArjayBalberan1
 
PPTX
gdscWorkShopJavascriptintroductions.pptx
sandeshshahapur
 
PPTX
Internet protocol second unit IIPPT.pptx
ssuser92282c
 
PPTX
Unit 3-Javascript.pptx
AmanJha533833
 
PPTX
13-IntroJavascript.pptxIntroduction to java script
gdckviksitbharat
 
PPTX
13-IntroJavascript.pptx
suchita74
 
PPTX
13-IntroJavascript.pptx
ShilpaBhojne
 
PPTX
13-IntroJavascript.pptx
ssuserd695d1
 
PPTX
Intro to javascript for web development.pptx
MarioCaday2
 
PDF
8.-Javascript-report powerpoint presentation
JohnLagman3
 
PPTX
POLITEKNIK MALAYSIA
Aiman Hud
 
PPT
lecture 6 javascript event and event handling.ppt
ULADATZ
 
PDF
Training javascript 2012 hcmut
University of Technology
 
Java script
Sanjay Gunjal
 
Introduction to web programming with JavaScript
T11 Sessions
 
Web technologies-course 07.pptx
Stefan Oprea
 
JavaScript_III.pptx
rashmiisrani1
 
JavascriptCOmpleteGuideCourseFromZero.pptx
AlaeddineTheljani
 
Monster JavaScript Course - 50+ projects and applications
Laurence Svekis ✔
 
Html JavaScript and CSS
Radhe Krishna Rajan
 
MYSQL DATABASE INTRODUCTION TO JAVASCRIPT.pptx
ArjayBalberan1
 
gdscWorkShopJavascriptintroductions.pptx
sandeshshahapur
 
Internet protocol second unit IIPPT.pptx
ssuser92282c
 
Unit 3-Javascript.pptx
AmanJha533833
 
13-IntroJavascript.pptxIntroduction to java script
gdckviksitbharat
 
13-IntroJavascript.pptx
suchita74
 
13-IntroJavascript.pptx
ShilpaBhojne
 
13-IntroJavascript.pptx
ssuserd695d1
 
Intro to javascript for web development.pptx
MarioCaday2
 
8.-Javascript-report powerpoint presentation
JohnLagman3
 
POLITEKNIK MALAYSIA
Aiman Hud
 
lecture 6 javascript event and event handling.ppt
ULADATZ
 
Training javascript 2012 hcmut
University of Technology
 
Ad

Recently uploaded (20)

PPTX
World First Cardiovascular & Thoracic CT Scanner
arineta37
 
PDF
Securiport - A Global Leader
Securiport
 
PDF
LEWIONICS SCO Company Profile UAE JULY 2025
Natalie Lewes
 
PPTX
25 Future Mega Trends Reshaping the World in 2025 and Beyond
presentifyai
 
PPTX
Why-Your-BPO-Startup-Must-Track-Attrition-from-Day-One.pptx.pptx
Orage technologies
 
PDF
20250703_A. Stotz All Weather Strategy - Performance review July
FINNOMENAMarketing
 
PPTX
Washington University of Health and Science A Choice You Can Trust
Washington University of Health and Science
 
PDF
Rostyslav Chayka: Управління командою за допомогою AI (UA)
Lviv Startup Club
 
PPTX
Build Wealth & Protect Your Legacy with Indexed Universal Life Insurance
iulfinancial6
 
PDF
Raman Bhaumik - A Passion For Service
Raman Bhaumik
 
DOCX
RECLAIM STOLEN CRYPTO REVIEW WITH RECUVA HACKER SOLUTIONS
camilamichaelj7
 
PPTX
2025 July - ABM for B2B in Hubspot - Demand Gen HUG.pptx
mjenkins13
 
PPTX
DECODING AI AGENTS AND WORKFLOW AUTOMATION FOR MODERN RECRUITMENT
José Kadlec
 
PDF
kcb-group-plc-2024-integrated-report-and-financial-statements (3).pdf
DanielNdegwa10
 
PDF
HOW TO RECOVER LOST CRYPTOCURRENCY - VISIT iBOLT CYBER HACKER COMPANY
diegovalentin771
 
PPTX
Hackathon - Technology - Idea Submission Template -HackerEarth.pptx
nanster236
 
PDF
LDM Recording for Yogi Goddess Projects Summer 2025
LDMMia GrandMaster
 
PDF
Gabino Barbosa - A Master Of Efficiency
Gabino Barbosa
 
PDF
Native Sons Of The Golden West - Boasts A Legacy Of Impactful Leadership
Native Sons of the Golden West
 
PDF
Two-phase direct-to-chip cooling - Parker Components
Parker Hannifin Corporation
 
World First Cardiovascular & Thoracic CT Scanner
arineta37
 
Securiport - A Global Leader
Securiport
 
LEWIONICS SCO Company Profile UAE JULY 2025
Natalie Lewes
 
25 Future Mega Trends Reshaping the World in 2025 and Beyond
presentifyai
 
Why-Your-BPO-Startup-Must-Track-Attrition-from-Day-One.pptx.pptx
Orage technologies
 
20250703_A. Stotz All Weather Strategy - Performance review July
FINNOMENAMarketing
 
Washington University of Health and Science A Choice You Can Trust
Washington University of Health and Science
 
Rostyslav Chayka: Управління командою за допомогою AI (UA)
Lviv Startup Club
 
Build Wealth & Protect Your Legacy with Indexed Universal Life Insurance
iulfinancial6
 
Raman Bhaumik - A Passion For Service
Raman Bhaumik
 
RECLAIM STOLEN CRYPTO REVIEW WITH RECUVA HACKER SOLUTIONS
camilamichaelj7
 
2025 July - ABM for B2B in Hubspot - Demand Gen HUG.pptx
mjenkins13
 
DECODING AI AGENTS AND WORKFLOW AUTOMATION FOR MODERN RECRUITMENT
José Kadlec
 
kcb-group-plc-2024-integrated-report-and-financial-statements (3).pdf
DanielNdegwa10
 
HOW TO RECOVER LOST CRYPTOCURRENCY - VISIT iBOLT CYBER HACKER COMPANY
diegovalentin771
 
Hackathon - Technology - Idea Submission Template -HackerEarth.pptx
nanster236
 
LDM Recording for Yogi Goddess Projects Summer 2025
LDMMia GrandMaster
 
Gabino Barbosa - A Master Of Efficiency
Gabino Barbosa
 
Native Sons Of The Golden West - Boasts A Legacy Of Impactful Leadership
Native Sons of the Golden West
 
Two-phase direct-to-chip cooling - Parker Components
Parker Hannifin Corporation
 
Ad

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