SlideShare a Scribd company logo
1 of 14
JAVASCRIPT
Chapter 4
THINGS TO DO IN JAVASCRIPT
• Display messages to the user as part of a web page, in the browser’s status line, or
in alert boxes.
• Validate the contents of a form and make calculations (for example, an order form
can automatically display a running total as you enter item quantities).
• Animate images or create images that change when you move the mouse over
them.
• Create ad banners that interact with the user, rather than simply displaying a
graphic.
• Detect features supported by browsers and perform advanced functions only on
browsers that support those features.
• Detect installed plug-ins and notify the user if a plug-in is required
• Modify all or part of a web page without requiring the user to reload it
• Display or interact with data retrieved from a remote server
JAVASCRIPT
Tells browser what to do
SAMPLE HTML WITH JAVASCRIPT
<!DOCTYPE html>
<html lang="en">
<head>
<title>A Spectacular Time!</title>
</head>
<body>
<h1>It is a Spectacular Time!</h1>
<p>What time is it, you ask?</p>
<p>Well, indeed it is: <br>
<script type="text/javascript">
var currentTime = new Date();
document.write(currentTime);
</script>
</p>
</body>
</html>
PLACES FOR JAVASCRIPT
• In the body of the page
• In the header of the page between <head> tags
• Within an HTML tag such as <body> or <form> - called event handling
• In a separate file, .js convention
EXTERNAL FILE JAVASCRIPT
<script type="text/javascript" src="filename.js"></script>
JAVASCRIPT EVENTS
<!DOCTYPE html>
<html lang="en">
<head>
<title>Event Test</title>
</head>
<body>
<h1>Event Test</h1>
<button type="button"
onclick="alert('You clicked the button.');">
Click Me!</button>
</body>
</html>
JS CAPABILITIES
• Validating forms – dates, zipcodes, email addresses, phone numbers, etc
• Special effects – drag&drop, fading transitions, games
• Remote Scripting (AJAX) – communication with web server
BASIC LANGUAGE CONCEPTS
• Statements
• now = new Date();
hours = now.getHours();
mins = now.getMinutes();
secs = now.getSeconds();
• Functions
• function alertMe() {
alert("I am alerting you!");
}
• Variables
• var food = "cheese";
• Objects
• They have properties and methods, similar to Java or C++ or Python
• Built in objects
• DOM (document object model – browser things)
• Custom objects – you create these
• Conditionals
• if (count == 1) {
alert("The countdown has reached 1.");
}
• Loops
• for (i=1; i<=10; i++) {
alert("Yes, it's yet another alert!");
}
• Event Handlers
EVENT HANDLERS
• Things that happen in the browser
• Some are user generated (mouse click, mouse over)
• Some are system generated (on load, timers)
• They involve an object and an action
• They can happen at any time, not sequential
<!DOCTYPE html>
<html lang="en">
<head>
<title>Simple Event Handler Example</title>
</head>
<body>
<h1>Simple Event Handler Example</h1>
<p><a href="http://www.google.com/"
onclick="alert('A-ha! An Event!');">Go to Google</a>
</p>
</body>
</html>
WHEN DO SCRIPTS RUN?
• Sets of <script> tags in <head> element are handled first
• Sets of <script> tags in <body> element are handled next, in sequence
• Event handlers are executed when the event happens
SYNTAX RULES
• Case sensitive
• Keywords, like for, if, are always lowercase
• Built-in objects are properly cased, like Math and Date
• DOM object names are usually lowercase but their methods are often properly case
with 1st letter lowercase, like setAttribute, getElementById
• For variable, object, function names – upper and lower case, numbers, _; must begin
with letter or _
• Reserved words
• Reference: https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Lexical_grammar
• Spacing – whitespace ignored; used for human readability
• Comments - // - single line /* */ multiple line
JSON
• JavaScript Object Notation
• Pronounced “jason” or “jay sawn”
• Not part of Javascript but common way to structure information
• var yourJSONObject = {
"param1":"value1",
"param2":"value2",
"param3":"value3"
}
• Commonly used to pass information via APIs – application programming interface
DEBUGGING
Use document.write(“xxxx”) to display program flow information
Configure your browser to display error messages – google to find out how

More Related Content

What's hot

`From Prototype to Drupal` by Andrew Ivasiv
`From Prototype to Drupal` by Andrew Ivasiv`From Prototype to Drupal` by Andrew Ivasiv
`From Prototype to Drupal` by Andrew IvasivLemberg Solutions
 
Meta Programming with JavaScript
Meta Programming with JavaScriptMeta Programming with JavaScript
Meta Programming with JavaScriptjeresig
 
Website Series 4 - JavaScript
Website Series 4 - JavaScriptWebsite Series 4 - JavaScript
Website Series 4 - JavaScriptEugene Yang
 
JavaServer Pages
JavaServer Pages JavaServer Pages
JavaServer Pages profbnk
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone InteractivityEric Steele
 
FYBSC IT Web Programming Unit III Events and Event Handlers
FYBSC IT Web Programming Unit III Events and Event HandlersFYBSC IT Web Programming Unit III Events and Event Handlers
FYBSC IT Web Programming Unit III Events and Event HandlersArti Parab Academics
 
BOOM Performance
BOOM PerformanceBOOM Performance
BOOM Performancedapulse
 
Magic Buttons - George Courtsunis
Magic Buttons - George CourtsunisMagic Buttons - George Courtsunis
Magic Buttons - George CourtsunisQuickBase, Inc.
 
HTML SERVER CONTROL - ASP.NET WITH C#
HTML SERVER CONTROL  - ASP.NET WITH C#HTML SERVER CONTROL  - ASP.NET WITH C#
HTML SERVER CONTROL - ASP.NET WITH C#priya Nithya
 
Web application using JSP
Web application using JSPWeb application using JSP
Web application using JSPKaml Sah
 
Resource Oriented Design
Resource Oriented DesignResource Oriented Design
Resource Oriented DesignGabriele Lana
 
Alfresco : Implementing Workflow
Alfresco : Implementing WorkflowAlfresco : Implementing Workflow
Alfresco : Implementing WorkflowWildan Maulana
 
Wellrailed - Cucumber tips
Wellrailed - Cucumber tipsWellrailed - Cucumber tips
Wellrailed - Cucumber tipsbreccan
 
Introduction to Django CMS
Introduction to Django CMS Introduction to Django CMS
Introduction to Django CMS Pim Van Heuven
 
JavaScript DOM Manipulations
JavaScript DOM ManipulationsJavaScript DOM Manipulations
JavaScript DOM ManipulationsYnon Perek
 

What's hot (18)

`From Prototype to Drupal` by Andrew Ivasiv
`From Prototype to Drupal` by Andrew Ivasiv`From Prototype to Drupal` by Andrew Ivasiv
`From Prototype to Drupal` by Andrew Ivasiv
 
Meta Programming with JavaScript
Meta Programming with JavaScriptMeta Programming with JavaScript
Meta Programming with JavaScript
 
Website Series 4 - JavaScript
Website Series 4 - JavaScriptWebsite Series 4 - JavaScript
Website Series 4 - JavaScript
 
JavaServer Pages
JavaServer Pages JavaServer Pages
JavaServer Pages
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone Interactivity
 
FYBSC IT Web Programming Unit III Events and Event Handlers
FYBSC IT Web Programming Unit III Events and Event HandlersFYBSC IT Web Programming Unit III Events and Event Handlers
FYBSC IT Web Programming Unit III Events and Event Handlers
 
BOOM Performance
BOOM PerformanceBOOM Performance
BOOM Performance
 
Javascript and DOM
Javascript and DOMJavascript and DOM
Javascript and DOM
 
BDD with cucumber
BDD with cucumberBDD with cucumber
BDD with cucumber
 
Magic Buttons - George Courtsunis
Magic Buttons - George CourtsunisMagic Buttons - George Courtsunis
Magic Buttons - George Courtsunis
 
HTML SERVER CONTROL - ASP.NET WITH C#
HTML SERVER CONTROL  - ASP.NET WITH C#HTML SERVER CONTROL  - ASP.NET WITH C#
HTML SERVER CONTROL - ASP.NET WITH C#
 
Web application using JSP
Web application using JSPWeb application using JSP
Web application using JSP
 
Resource Oriented Design
Resource Oriented DesignResource Oriented Design
Resource Oriented Design
 
Alfresco : Implementing Workflow
Alfresco : Implementing WorkflowAlfresco : Implementing Workflow
Alfresco : Implementing Workflow
 
Wellrailed - Cucumber tips
Wellrailed - Cucumber tipsWellrailed - Cucumber tips
Wellrailed - Cucumber tips
 
Web&java. jsp
Web&java. jspWeb&java. jsp
Web&java. jsp
 
Introduction to Django CMS
Introduction to Django CMS Introduction to Django CMS
Introduction to Django CMS
 
JavaScript DOM Manipulations
JavaScript DOM ManipulationsJavaScript DOM Manipulations
JavaScript DOM Manipulations
 

Similar to Upstate CSCI 450 WebDev Chapter 4

Similar to Upstate CSCI 450 WebDev Chapter 4 (20)

JAVASCRIPT 1.pptx.pptx
JAVASCRIPT 1.pptx.pptxJAVASCRIPT 1.pptx.pptx
JAVASCRIPT 1.pptx.pptx
 
jQuery
jQueryjQuery
jQuery
 
Client Web
Client WebClient Web
Client Web
 
JavaScriptL18 [Autosaved].pptx
JavaScriptL18 [Autosaved].pptxJavaScriptL18 [Autosaved].pptx
JavaScriptL18 [Autosaved].pptx
 
Java Script (Module 1).pptx
Java Script (Module 1).pptxJava Script (Module 1).pptx
Java Script (Module 1).pptx
 
JavaScript - Part-1
JavaScript - Part-1JavaScript - Part-1
JavaScript - Part-1
 
前端概述
前端概述前端概述
前端概述
 
Web Components: The future of Web Application Development
Web Components: The future of Web Application DevelopmentWeb Components: The future of Web Application Development
Web Components: The future of Web Application Development
 
JavaScript Training
JavaScript TrainingJavaScript Training
JavaScript Training
 
Intro to java script
Intro to java scriptIntro to java script
Intro to java script
 
Java script
Java scriptJava script
Java script
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Java script
Java scriptJava script
Java script
 
jQuery : Events are where it happens!
jQuery : Events are where it happens!jQuery : Events are where it happens!
jQuery : Events are where it happens!
 
JavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & Implementation
 
Introduction to JavaScript (1).ppt
Introduction to JavaScript (1).pptIntroduction to JavaScript (1).ppt
Introduction to JavaScript (1).ppt
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Jsf Ajax
Jsf AjaxJsf Ajax
Jsf Ajax
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
 

More from DanWooster1

Upstate CSCI 540 Agile Development
Upstate CSCI 540 Agile DevelopmentUpstate CSCI 540 Agile Development
Upstate CSCI 540 Agile DevelopmentDanWooster1
 
Upstate CSCI 540 Unit testing
Upstate CSCI 540 Unit testingUpstate CSCI 540 Unit testing
Upstate CSCI 540 Unit testingDanWooster1
 
Upstate CSCI 450 WebDev Chapter 9
Upstate CSCI 450 WebDev Chapter 9Upstate CSCI 450 WebDev Chapter 9
Upstate CSCI 450 WebDev Chapter 9DanWooster1
 
Upstate CSCI 450 WebDev Chapter 3
Upstate CSCI 450 WebDev Chapter 3Upstate CSCI 450 WebDev Chapter 3
Upstate CSCI 450 WebDev Chapter 3DanWooster1
 
Upstate CSCI 450 WebDev Chapter 2
Upstate CSCI 450 WebDev Chapter 2Upstate CSCI 450 WebDev Chapter 2
Upstate CSCI 450 WebDev Chapter 2DanWooster1
 
Upstate CSCI 450 WebDev Chapter 1
Upstate CSCI 450 WebDev Chapter 1Upstate CSCI 450 WebDev Chapter 1
Upstate CSCI 450 WebDev Chapter 1DanWooster1
 
Upstate CSCI 525 Data Mining Chapter 3
Upstate CSCI 525 Data Mining Chapter 3Upstate CSCI 525 Data Mining Chapter 3
Upstate CSCI 525 Data Mining Chapter 3DanWooster1
 
Upstate CSCI 525 Data Mining Chapter 2
Upstate CSCI 525 Data Mining Chapter 2Upstate CSCI 525 Data Mining Chapter 2
Upstate CSCI 525 Data Mining Chapter 2DanWooster1
 
Upstate CSCI 525 Data Mining Chapter 1
Upstate CSCI 525 Data Mining Chapter 1Upstate CSCI 525 Data Mining Chapter 1
Upstate CSCI 525 Data Mining Chapter 1DanWooster1
 
Upstate CSCI 200 Java Chapter 8 - Arrays
Upstate CSCI 200 Java Chapter 8 - ArraysUpstate CSCI 200 Java Chapter 8 - Arrays
Upstate CSCI 200 Java Chapter 8 - ArraysDanWooster1
 
Upstate CSCI 200 Java Chapter 7 - OOP
Upstate CSCI 200 Java Chapter 7 - OOPUpstate CSCI 200 Java Chapter 7 - OOP
Upstate CSCI 200 Java Chapter 7 - OOPDanWooster1
 
CSCI 200 Java Chapter 03 Using Classes
CSCI 200 Java Chapter 03 Using ClassesCSCI 200 Java Chapter 03 Using Classes
CSCI 200 Java Chapter 03 Using ClassesDanWooster1
 
CSCI 200 Java Chapter 02 Data & Expressions
CSCI 200 Java Chapter 02 Data & ExpressionsCSCI 200 Java Chapter 02 Data & Expressions
CSCI 200 Java Chapter 02 Data & ExpressionsDanWooster1
 
CSCI 200 Java Chapter 01
CSCI 200 Java Chapter 01CSCI 200 Java Chapter 01
CSCI 200 Java Chapter 01DanWooster1
 
CSCI 238 Chapter 08 Arrays Textbook Slides
CSCI 238 Chapter 08 Arrays Textbook SlidesCSCI 238 Chapter 08 Arrays Textbook Slides
CSCI 238 Chapter 08 Arrays Textbook SlidesDanWooster1
 
Chapter 6 - More conditionals and loops
Chapter 6 - More conditionals and loopsChapter 6 - More conditionals and loops
Chapter 6 - More conditionals and loopsDanWooster1
 
Upstate CSCI 450 jQuery
Upstate CSCI 450 jQueryUpstate CSCI 450 jQuery
Upstate CSCI 450 jQueryDanWooster1
 
Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13DanWooster1
 
Upstate CSCI 450 PHP
Upstate CSCI 450 PHPUpstate CSCI 450 PHP
Upstate CSCI 450 PHPDanWooster1
 
CSCI 238 Chapter 07 - Classes
CSCI 238 Chapter 07 - ClassesCSCI 238 Chapter 07 - Classes
CSCI 238 Chapter 07 - ClassesDanWooster1
 

More from DanWooster1 (20)

Upstate CSCI 540 Agile Development
Upstate CSCI 540 Agile DevelopmentUpstate CSCI 540 Agile Development
Upstate CSCI 540 Agile Development
 
Upstate CSCI 540 Unit testing
Upstate CSCI 540 Unit testingUpstate CSCI 540 Unit testing
Upstate CSCI 540 Unit testing
 
Upstate CSCI 450 WebDev Chapter 9
Upstate CSCI 450 WebDev Chapter 9Upstate CSCI 450 WebDev Chapter 9
Upstate CSCI 450 WebDev Chapter 9
 
Upstate CSCI 450 WebDev Chapter 3
Upstate CSCI 450 WebDev Chapter 3Upstate CSCI 450 WebDev Chapter 3
Upstate CSCI 450 WebDev Chapter 3
 
Upstate CSCI 450 WebDev Chapter 2
Upstate CSCI 450 WebDev Chapter 2Upstate CSCI 450 WebDev Chapter 2
Upstate CSCI 450 WebDev Chapter 2
 
Upstate CSCI 450 WebDev Chapter 1
Upstate CSCI 450 WebDev Chapter 1Upstate CSCI 450 WebDev Chapter 1
Upstate CSCI 450 WebDev Chapter 1
 
Upstate CSCI 525 Data Mining Chapter 3
Upstate CSCI 525 Data Mining Chapter 3Upstate CSCI 525 Data Mining Chapter 3
Upstate CSCI 525 Data Mining Chapter 3
 
Upstate CSCI 525 Data Mining Chapter 2
Upstate CSCI 525 Data Mining Chapter 2Upstate CSCI 525 Data Mining Chapter 2
Upstate CSCI 525 Data Mining Chapter 2
 
Upstate CSCI 525 Data Mining Chapter 1
Upstate CSCI 525 Data Mining Chapter 1Upstate CSCI 525 Data Mining Chapter 1
Upstate CSCI 525 Data Mining Chapter 1
 
Upstate CSCI 200 Java Chapter 8 - Arrays
Upstate CSCI 200 Java Chapter 8 - ArraysUpstate CSCI 200 Java Chapter 8 - Arrays
Upstate CSCI 200 Java Chapter 8 - Arrays
 
Upstate CSCI 200 Java Chapter 7 - OOP
Upstate CSCI 200 Java Chapter 7 - OOPUpstate CSCI 200 Java Chapter 7 - OOP
Upstate CSCI 200 Java Chapter 7 - OOP
 
CSCI 200 Java Chapter 03 Using Classes
CSCI 200 Java Chapter 03 Using ClassesCSCI 200 Java Chapter 03 Using Classes
CSCI 200 Java Chapter 03 Using Classes
 
CSCI 200 Java Chapter 02 Data & Expressions
CSCI 200 Java Chapter 02 Data & ExpressionsCSCI 200 Java Chapter 02 Data & Expressions
CSCI 200 Java Chapter 02 Data & Expressions
 
CSCI 200 Java Chapter 01
CSCI 200 Java Chapter 01CSCI 200 Java Chapter 01
CSCI 200 Java Chapter 01
 
CSCI 238 Chapter 08 Arrays Textbook Slides
CSCI 238 Chapter 08 Arrays Textbook SlidesCSCI 238 Chapter 08 Arrays Textbook Slides
CSCI 238 Chapter 08 Arrays Textbook Slides
 
Chapter 6 - More conditionals and loops
Chapter 6 - More conditionals and loopsChapter 6 - More conditionals and loops
Chapter 6 - More conditionals and loops
 
Upstate CSCI 450 jQuery
Upstate CSCI 450 jQueryUpstate CSCI 450 jQuery
Upstate CSCI 450 jQuery
 
Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13
 
Upstate CSCI 450 PHP
Upstate CSCI 450 PHPUpstate CSCI 450 PHP
Upstate CSCI 450 PHP
 
CSCI 238 Chapter 07 - Classes
CSCI 238 Chapter 07 - ClassesCSCI 238 Chapter 07 - Classes
CSCI 238 Chapter 07 - Classes
 

Recently uploaded

Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 

Recently uploaded (20)

Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 

Upstate CSCI 450 WebDev Chapter 4

  • 2. THINGS TO DO IN JAVASCRIPT • Display messages to the user as part of a web page, in the browser’s status line, or in alert boxes. • Validate the contents of a form and make calculations (for example, an order form can automatically display a running total as you enter item quantities). • Animate images or create images that change when you move the mouse over them. • Create ad banners that interact with the user, rather than simply displaying a graphic. • Detect features supported by browsers and perform advanced functions only on browsers that support those features. • Detect installed plug-ins and notify the user if a plug-in is required • Modify all or part of a web page without requiring the user to reload it • Display or interact with data retrieved from a remote server
  • 4. SAMPLE HTML WITH JAVASCRIPT <!DOCTYPE html> <html lang="en"> <head> <title>A Spectacular Time!</title> </head> <body> <h1>It is a Spectacular Time!</h1> <p>What time is it, you ask?</p> <p>Well, indeed it is: <br> <script type="text/javascript"> var currentTime = new Date(); document.write(currentTime); </script> </p> </body> </html>
  • 5. PLACES FOR JAVASCRIPT • In the body of the page • In the header of the page between <head> tags • Within an HTML tag such as <body> or <form> - called event handling • In a separate file, .js convention
  • 6. EXTERNAL FILE JAVASCRIPT <script type="text/javascript" src="filename.js"></script>
  • 7. JAVASCRIPT EVENTS <!DOCTYPE html> <html lang="en"> <head> <title>Event Test</title> </head> <body> <h1>Event Test</h1> <button type="button" onclick="alert('You clicked the button.');"> Click Me!</button> </body> </html>
  • 8. JS CAPABILITIES • Validating forms – dates, zipcodes, email addresses, phone numbers, etc • Special effects – drag&drop, fading transitions, games • Remote Scripting (AJAX) – communication with web server
  • 9. BASIC LANGUAGE CONCEPTS • Statements • now = new Date(); hours = now.getHours(); mins = now.getMinutes(); secs = now.getSeconds(); • Functions • function alertMe() { alert("I am alerting you!"); } • Variables • var food = "cheese"; • Objects • They have properties and methods, similar to Java or C++ or Python • Built in objects • DOM (document object model – browser things) • Custom objects – you create these • Conditionals • if (count == 1) { alert("The countdown has reached 1."); } • Loops • for (i=1; i<=10; i++) { alert("Yes, it's yet another alert!"); } • Event Handlers
  • 10. EVENT HANDLERS • Things that happen in the browser • Some are user generated (mouse click, mouse over) • Some are system generated (on load, timers) • They involve an object and an action • They can happen at any time, not sequential <!DOCTYPE html> <html lang="en"> <head> <title>Simple Event Handler Example</title> </head> <body> <h1>Simple Event Handler Example</h1> <p><a href="http://www.google.com/" onclick="alert('A-ha! An Event!');">Go to Google</a> </p> </body> </html>
  • 11. WHEN DO SCRIPTS RUN? • Sets of <script> tags in <head> element are handled first • Sets of <script> tags in <body> element are handled next, in sequence • Event handlers are executed when the event happens
  • 12. SYNTAX RULES • Case sensitive • Keywords, like for, if, are always lowercase • Built-in objects are properly cased, like Math and Date • DOM object names are usually lowercase but their methods are often properly case with 1st letter lowercase, like setAttribute, getElementById • For variable, object, function names – upper and lower case, numbers, _; must begin with letter or _ • Reserved words • Reference: https://developer.mozilla.org/en- US/docs/Web/JavaScript/Reference/Lexical_grammar • Spacing – whitespace ignored; used for human readability • Comments - // - single line /* */ multiple line
  • 13. JSON • JavaScript Object Notation • Pronounced “jason” or “jay sawn” • Not part of Javascript but common way to structure information • var yourJSONObject = { "param1":"value1", "param2":"value2", "param3":"value3" } • Commonly used to pass information via APIs – application programming interface
  • 14. DEBUGGING Use document.write(“xxxx”) to display program flow information Configure your browser to display error messages – google to find out how