SlideShare a Scribd company logo
1 of 23
Totally different
A full programming language
Much harder!
A compiled language
Independent of the web
Sometimes used together
WHAT IS JAVA?
Browsers have limited functionality
Text, images, tables, frames
JavaScript allows for interactivity
Browser/page manipulation
Reacting to user actions
A type of programming language
Easy to learn
Developed by Netscape
WHAT IS JAVASCRIPT?
Java - Programming Language (PL)
Interactive Web Graphics
Creating web browser applications
Writing stand-alone applications
JavaScript - Scripting Language
Runs within the context of the Web browser
Customizing pages based on browser version
Visual Feedback to user actions
Validating data entered on HTML Forms
In reality, Java and JavaScript are unrelated…
JAVA VS JAVASCRIPT
JavaScript is an implementation of the ECMAScript language standard.
ECMA-262 is the official JavaScript standard.
JavaScript was invented by Brendan Eich at Netscape (with Navigator 2.0),
and has appeared in all browsers since 1996.
The official standardization was adopted by the ECMA organization (an
industry standardization association) in 1997.
The ECMA standard (called ECMAScript-262) was approved as an
international ISO (ISO/IEC 16262) standard in 1998.
The development is still in progress.
ECMA-European Computer Manufacturers Association
JAVASCRIPT = ECMASCRIPT
JavaScript is -
-- NOT Java
-- NOT typically used for server-side processing, like PHP (PHP Hypertext Preprocessor ) or
ASP (Active Server Pages)
-- NOT good for data-processing
-- NOT as difficult to master as programming languages like C# or Java
WHAT JAVASCRIPT IS NOT
JavaScript gives HTML designers a programming tool - HTML authors are
normally not programmers, but JavaScript is a scripting language with a very simple
syntax! Almost anyone can put small "snippets" of code into their HTML pages
JavaScript can react to events - A JavaScript can be set to execute when something
happens, like when a page has finished loading or when a user clicks on an HTML
element
WHAT CAN
JAVASCRIPT DO?
JavaScript can manipulate HTML elements - A JavaScript can read
and change the content of an HTML element
JavaScript can be used to validate data - A JavaScript can be used to
validate form input
JavaScript can be used to detect the visitor's browser - A JavaScript
can be used to detect the visitor's browser, and - depending on the
browser - load another page specifically designed for that browser
JavaScript can be used to create cookies - A JavaScript can be used to
store and retrieve information on the visitor's computer
CONT- JAVASCRIPT DO’S
Special syntax to learn
Learn the basics and then use other people's
(lots of free sites)
Write it in a text editor, view results in browser
You need to revise your HTML
You need patience and good eyesight!
LEARNING JAVASCRIPT
Embedded within HTML page
View source
Executes on client
Fast, no connection needed once loaded
Simple programming statements combined with HTML tags
Interpreted (not compiled)
No special tools required
HOW DOES JS WORK?
-- JavaScript works with HTML & CSS (Cascading Style Sheets)
-- Content is separated from Presentation & Behavior
“THREE LEGGED STOOL”
HTML
Content
CSS
(Cascading Style
Sheets)
Presentation
JavaScript
Behavior
The simplest JavaScript "Hello World" program is pretty much as follows:
1: <script type="text/javascript">
2: <!-- to hide script contents from old browsers
3: document.write("Hello World!")
4: // end hiding contents from old browsers -->
5: </script>
SOURCE CODE
Lines 1 and 5 are the HTML tags (<script> ... </script>) that define
what's between them as a script of some sort that is to be executed by
your browser.
HTML itself doesn't care what kind of script it is and other scripting
languages besides JavaScript, e.g. VBScript or TCL, may be supported by
a browser. In this case the type attribute of the SCRIPT tag declares the
script to be JavaScript. These are called "client-side" scripts to distinguish
them from "server-side" scripts that would be executed by the HTTP
server before it delivers the document.
Note: You may see the language="JavaScript" attribute appearing in
a SCRIPT tag. 
DEFINITION:
Lines 2 and 4 are very odd looking. Line 2 starts an HTML comment, which ends at the
end of line 4.
Thus everything between them looks like an HTML comment to browsers that don't
support JavaScript.
But a JavaScript interpreter will just ignore line 3, and will treat line 4 as a JavaScript
comment because it starts with "//".
DEF-2
Improve appearance
Especially graphics
Visual feedback
Site navigation
Perform calculations
Validation of input
Other technologies
JAVASCRIPT ALLOWS
INTERACTIVITY
<html>
<head><title>My Page</title></head>
<body>
<script language="JavaScript">
document.write('This is my first →
JavaScript Page');
</script>
</body>
</html>
JAVASCRIPT STATEMENTS
Note the symbol for
line continuation
<html>
<head><title>My Page</title></head>
<body>
<script language=“JavaScript">
document.write('<h1>This is my first →
JavaScript Page</h1>');
</script>
</body>
</html>
JAVASCRIPT STATEMENTS
HTML written
inside JavaScript
<html>
<head><title>My Page</title></head>
<body>
<p>
<a href="myfile.html">My Page</a>
<br />
<a href="myfile.html"
onMouseover="window.alert('Hello');">
My Page</A>
</p>
</body>
</html>
JAVASCRIPT STATEMENTS
JavaScript written
inside HTML
An Event
<script language="JavaScript">
window.prompt('Enter your name:','');
</script>
<form>
<input type="button" Value="Press"
onClick="window.alert('Hello');">
</form>
EXAMPLE STATEMENTS
Another event
Note quotes: " and '
JavaScript is very good at processing user input in the web browser
HTML <form> elements receive input
Forms and form elements have unique names
Each unique element can be identified
Uses JavaScript Document Object Model (DOM)
HTML FORMS AND JAVASCRIPT
<form name="addressform">
Name: <input name="yourname"><br />
Phone: <input name="phone"><br />
Email: <input name="email"><br />
</form>
NAMING FORM ELEMENTS IN HTML
document.formname.elementname.value
Thus:
document.addressform.yourname.value
document.addressform.phone.value
document.addressform.email.value
FORMS AND JAVASCRIPT
Personalising an alert box
<form name="alertform">
Enter your name:
<input type="text" name="yourname">
<input type="button" value= "Go"
onClick="window.alert('Hello ' + →
document.alertform.yourname.value);">
</form>
USING FORM DATA

More Related Content

What's hot

Java script writing javascript
Java script writing javascriptJava script writing javascript
Java script writing javascript
Jesus Obenita Jr.
 
Monster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applicationsMonster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applications
Laurence Svekis ✔
 
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
tutorialsruby
 

What's hot (18)

Introduction to java_script
Introduction to java_scriptIntroduction to java_script
Introduction to java_script
 
Java script by Act Academy
Java script by Act AcademyJava script by Act Academy
Java script by Act Academy
 
Java script programs
Java script programsJava script programs
Java script programs
 
1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentals
 
JavaScript Jump Start 20220214
JavaScript Jump Start 20220214JavaScript Jump Start 20220214
JavaScript Jump Start 20220214
 
Java Script An Introduction By HWA
Java Script An Introduction By HWAJava Script An Introduction By HWA
Java Script An Introduction By HWA
 
Javascript by geetanjali
Javascript by geetanjaliJavascript by geetanjali
Javascript by geetanjali
 
Javascript tutorial
Javascript tutorialJavascript tutorial
Javascript tutorial
 
Java script writing javascript
Java script writing javascriptJava script writing javascript
Java script writing javascript
 
Javascript
JavascriptJavascript
Javascript
 
Java script
Java scriptJava script
Java script
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
 
JavaScript - Part-1
JavaScript - Part-1JavaScript - Part-1
JavaScript - Part-1
 
JavaScript Introduction
JavaScript IntroductionJavaScript Introduction
JavaScript Introduction
 
Monster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applicationsMonster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applications
 
JavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive CodeJavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive Code
 
Test2
Test2Test2
Test2
 
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
 

Viewers also liked (17)

Static and dynamic polymorphism
Static and dynamic polymorphismStatic and dynamic polymorphism
Static and dynamic polymorphism
 
Asp .net Jquery
Asp .net JqueryAsp .net Jquery
Asp .net Jquery
 
Oop's in php
Oop's in php Oop's in php
Oop's in php
 
C language
C language C language
C language
 
Análisis de la guía de trabajo I
Análisis de la guía de trabajo IAnálisis de la guía de trabajo I
Análisis de la guía de trabajo I
 
Phonegap android
Phonegap androidPhonegap android
Phonegap android
 
css and wordpress
css and wordpresscss and wordpress
css and wordpress
 
Internet with HTML
Internet with HTMLInternet with HTML
Internet with HTML
 
Jquery Preparation
Jquery PreparationJquery Preparation
Jquery Preparation
 
Architecture of net framework
Architecture of net frameworkArchitecture of net framework
Architecture of net framework
 
Desarrollo Sustentable Distrito Federal
Desarrollo Sustentable  Distrito Federal Desarrollo Sustentable  Distrito Federal
Desarrollo Sustentable Distrito Federal
 
Machote terminado
Machote  terminadoMachote  terminado
Machote terminado
 
Mobile application development
Mobile application developmentMobile application development
Mobile application development
 
Html Presentation
Html PresentationHtml Presentation
Html Presentation
 
Ccna security
Ccna security Ccna security
Ccna security
 
Data mining and data warehousing
Data mining and data warehousingData mining and data warehousing
Data mining and data warehousing
 
Database management system presentation
Database management system presentation Database management system presentation
Database management system presentation
 

Similar to Java script

Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
ch samaram
 

Similar to Java script (20)

Web programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh MalothWeb programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh Maloth
 
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
 
Java script
Java scriptJava script
Java script
 
Unit 4 Java script.pptx
Unit 4 Java script.pptxUnit 4 Java script.pptx
Unit 4 Java script.pptx
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
 
JavaScript New Tutorial Class XI and XII.pptx
JavaScript New Tutorial Class XI and XII.pptxJavaScript New Tutorial Class XI and XII.pptx
JavaScript New Tutorial Class XI and XII.pptx
 
Session vii(java scriptbasics)
Session vii(java scriptbasics)Session vii(java scriptbasics)
Session vii(java scriptbasics)
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
 
Front End Development | Introduction
Front End Development | IntroductionFront End Development | Introduction
Front End Development | Introduction
 
Empowerment Technologies Lecture 11 (Philippines SHS)
Empowerment Technologies Lecture 11 (Philippines SHS)Empowerment Technologies Lecture 11 (Philippines SHS)
Empowerment Technologies Lecture 11 (Philippines SHS)
 
Javascript
JavascriptJavascript
Javascript
 
Javascript 01 (js)
Javascript 01 (js)Javascript 01 (js)
Javascript 01 (js)
 
06 Javascript
06 Javascript06 Javascript
06 Javascript
 
introduction to js
introduction to jsintroduction to js
introduction to js
 
8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentation8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentation
 
JavaScript - Getting Started.pptx
JavaScript - Getting Started.pptxJavaScript - Getting Started.pptx
JavaScript - Getting Started.pptx
 
Java script Session No 1
Java script Session No 1Java script Session No 1
Java script Session No 1
 
JS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTINGJS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTING
 
Introduction to Web Development
Introduction to Web DevelopmentIntroduction to Web Development
Introduction to Web Development
 

More from umesh patil (19)

Array in c language
Array in c languageArray in c language
Array in c language
 
Array in c language
Array in c language Array in c language
Array in c language
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
Introduction to asp .net
Introduction to asp .netIntroduction to asp .net
Introduction to asp .net
 
Html and css presentation
Html and css presentationHtml and css presentation
Html and css presentation
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
Oops and c fundamentals
Oops and c fundamentals Oops and c fundamentals
Oops and c fundamentals
 
Function in c program
Function in c programFunction in c program
Function in c program
 
css and wordpress
css and wordpresscss and wordpress
css and wordpress
 
Php vs asp
Php vs aspPhp vs asp
Php vs asp
 
Ccna security
Ccna security Ccna security
Ccna security
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
C language
C languageC language
C language
 
Array in c language
Array in c language Array in c language
Array in c language
 
Visual basic
Visual basicVisual basic
Visual basic
 
Introduction to asp .net
Introduction to asp .netIntroduction to asp .net
Introduction to asp .net
 
Css
Css Css
Css
 
Html basic tags
Html basic tagsHtml basic tags
Html basic tags
 

Recently uploaded

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 

Java script

  • 1.
  • 2. Totally different A full programming language Much harder! A compiled language Independent of the web Sometimes used together WHAT IS JAVA?
  • 3. Browsers have limited functionality Text, images, tables, frames JavaScript allows for interactivity Browser/page manipulation Reacting to user actions A type of programming language Easy to learn Developed by Netscape WHAT IS JAVASCRIPT?
  • 4. Java - Programming Language (PL) Interactive Web Graphics Creating web browser applications Writing stand-alone applications JavaScript - Scripting Language Runs within the context of the Web browser Customizing pages based on browser version Visual Feedback to user actions Validating data entered on HTML Forms In reality, Java and JavaScript are unrelated… JAVA VS JAVASCRIPT
  • 5. JavaScript is an implementation of the ECMAScript language standard. ECMA-262 is the official JavaScript standard. JavaScript was invented by Brendan Eich at Netscape (with Navigator 2.0), and has appeared in all browsers since 1996. The official standardization was adopted by the ECMA organization (an industry standardization association) in 1997. The ECMA standard (called ECMAScript-262) was approved as an international ISO (ISO/IEC 16262) standard in 1998. The development is still in progress. ECMA-European Computer Manufacturers Association JAVASCRIPT = ECMASCRIPT
  • 6. JavaScript is - -- NOT Java -- NOT typically used for server-side processing, like PHP (PHP Hypertext Preprocessor ) or ASP (Active Server Pages) -- NOT good for data-processing -- NOT as difficult to master as programming languages like C# or Java WHAT JAVASCRIPT IS NOT
  • 7. JavaScript gives HTML designers a programming tool - HTML authors are normally not programmers, but JavaScript is a scripting language with a very simple syntax! Almost anyone can put small "snippets" of code into their HTML pages JavaScript can react to events - A JavaScript can be set to execute when something happens, like when a page has finished loading or when a user clicks on an HTML element WHAT CAN JAVASCRIPT DO?
  • 8. JavaScript can manipulate HTML elements - A JavaScript can read and change the content of an HTML element JavaScript can be used to validate data - A JavaScript can be used to validate form input JavaScript can be used to detect the visitor's browser - A JavaScript can be used to detect the visitor's browser, and - depending on the browser - load another page specifically designed for that browser JavaScript can be used to create cookies - A JavaScript can be used to store and retrieve information on the visitor's computer CONT- JAVASCRIPT DO’S
  • 9. Special syntax to learn Learn the basics and then use other people's (lots of free sites) Write it in a text editor, view results in browser You need to revise your HTML You need patience and good eyesight! LEARNING JAVASCRIPT
  • 10. Embedded within HTML page View source Executes on client Fast, no connection needed once loaded Simple programming statements combined with HTML tags Interpreted (not compiled) No special tools required HOW DOES JS WORK?
  • 11. -- JavaScript works with HTML & CSS (Cascading Style Sheets) -- Content is separated from Presentation & Behavior “THREE LEGGED STOOL” HTML Content CSS (Cascading Style Sheets) Presentation JavaScript Behavior
  • 12. The simplest JavaScript "Hello World" program is pretty much as follows: 1: <script type="text/javascript"> 2: <!-- to hide script contents from old browsers 3: document.write("Hello World!") 4: // end hiding contents from old browsers --> 5: </script> SOURCE CODE
  • 13. Lines 1 and 5 are the HTML tags (<script> ... </script>) that define what's between them as a script of some sort that is to be executed by your browser. HTML itself doesn't care what kind of script it is and other scripting languages besides JavaScript, e.g. VBScript or TCL, may be supported by a browser. In this case the type attribute of the SCRIPT tag declares the script to be JavaScript. These are called "client-side" scripts to distinguish them from "server-side" scripts that would be executed by the HTTP server before it delivers the document. Note: You may see the language="JavaScript" attribute appearing in a SCRIPT tag.  DEFINITION:
  • 14. Lines 2 and 4 are very odd looking. Line 2 starts an HTML comment, which ends at the end of line 4. Thus everything between them looks like an HTML comment to browsers that don't support JavaScript. But a JavaScript interpreter will just ignore line 3, and will treat line 4 as a JavaScript comment because it starts with "//". DEF-2
  • 15. Improve appearance Especially graphics Visual feedback Site navigation Perform calculations Validation of input Other technologies JAVASCRIPT ALLOWS INTERACTIVITY
  • 16. <html> <head><title>My Page</title></head> <body> <script language="JavaScript"> document.write('This is my first → JavaScript Page'); </script> </body> </html> JAVASCRIPT STATEMENTS Note the symbol for line continuation
  • 17. <html> <head><title>My Page</title></head> <body> <script language=“JavaScript"> document.write('<h1>This is my first → JavaScript Page</h1>'); </script> </body> </html> JAVASCRIPT STATEMENTS HTML written inside JavaScript
  • 18. <html> <head><title>My Page</title></head> <body> <p> <a href="myfile.html">My Page</a> <br /> <a href="myfile.html" onMouseover="window.alert('Hello');"> My Page</A> </p> </body> </html> JAVASCRIPT STATEMENTS JavaScript written inside HTML An Event
  • 19. <script language="JavaScript"> window.prompt('Enter your name:',''); </script> <form> <input type="button" Value="Press" onClick="window.alert('Hello');"> </form> EXAMPLE STATEMENTS Another event Note quotes: " and '
  • 20. JavaScript is very good at processing user input in the web browser HTML <form> elements receive input Forms and form elements have unique names Each unique element can be identified Uses JavaScript Document Object Model (DOM) HTML FORMS AND JAVASCRIPT
  • 21. <form name="addressform"> Name: <input name="yourname"><br /> Phone: <input name="phone"><br /> Email: <input name="email"><br /> </form> NAMING FORM ELEMENTS IN HTML
  • 23. Personalising an alert box <form name="alertform"> Enter your name: <input type="text" name="yourname"> <input type="button" value= "Go" onClick="window.alert('Hello ' + → document.alertform.yourname.value);"> </form> USING FORM DATA

Editor's Notes

  1. This talk introduces the JavaScript language. © Netskills, University of Newcastle Copyright in the whole and every part of this Courseware whether in the form of a written manual,document, software program, service or otherwise belongs to the University of Newcastle upon Tyne (&amp;quot;the Owner&amp;quot;) and may not be used, sold, licensed, transferred, copied or reproduced in whole or in part in any manner or form or in or on any media to any person other than in accordance with the terms of the Owner&amp;apos;s Licence Agreement or otherwise without the prior written consent of the Owner. All use of this material is governed by the Owner&amp;apos;s Standard Licence Agreement together with the appropriate Schedule. The following are available: A Standard Licence Schedule to cover all use including all for-profit use by any type of organisation and all use by non-educational establishments An Educational Licence Schedule for not-for-profit internal use only by a recognised educational establishment The Netskills logo and this copyright notice must be included in any copy or adaptation. Netskills is a trademark of Netskills, University of Newcastle
  2. Java is often confused with JavaScript. JavaScript was originally called LiveScript, but due to the popularity of Java at the time, it was renamed JavaScript . Java is different from JavaScript in a number of significant areas: Java is a full programming language which can do just about anything - JavaScript isn&amp;apos;t and can only do relatively simple things. Java is much harder to learn and takes much longer to master. Java is compiled. The language is not &amp;apos;embedded&amp;apos; or written in the page - it is self-contained as a separate file. Java can be used/written totally independently from the web - JavaScript works with web browsers only. They are sometimes used together - JavaScript can be used to &amp;apos;control&amp;apos; or configure Java &amp;apos;applets&amp;apos;. This talk does not cover Java in any more detail. A separate Netskills Training Module investigates the use of Java applets.
  3. When the web was conceived, browsers were limited to text and image - later tables and frames. The extent to which they provided interactivity with the user was very limited. JavaScript was developed by Netscape as a simple programming language (often referred to as a scripting language). It is easy to learn and small sections of JavaScript can be added to a web page rather than needing to develop complicated programs. It was specially designed for web page interaction and manipulating the web browser and page elements. It is often used to respond to user actions such as mouse clicks. Although developed by Netscape, and other variants exist, such as Jscript from Microsoft, a standard has been developed by the European Computer Manufacturers Association. It is known as ECMAScript, using the standard ECMA262, which can be found fully documented at the address on the slide.
  4. To learn JavaScript you will need to learn some of its language syntax. However, a good strategy is to learn the basics, and then use and adapt other people&amp;apos;s JavaScript. There are plenty of sites on the internet offering free JavaScript (see slide 4) with the calculator example. Other useful addresses are provided in the notes of last slide. As with HTML, JavaScript can be written in a text editor and viewed in a browser. As it is a programming language the syntax is quite strict (compared to HTML). It is also a good idea to make sure your HTML is up to scratch as this will save you time. The hands-on exercises contain an refresher exercise on HTML forms.
  5. JavaScript is embedded/included within HTML. You can often see JavaScript in the source of a web page or it is provided for information on the page as with the calculator example. JavaScript is mainly used as a client-side language - it downloads with the web page. Once the page has downloaded and is on the users&amp;apos; machine, it is actually the web browser which then interprets the JavaScript instructions. JavaScript pages run quickly, you are not relying on an internet connection to a web server. Short pieces of JavaScript can be combined with HTML without the need to develop a fully blown program. There are two types of computer language, compiled and interpreted. To write or edit a compiled language requires a special piece of software called a compiler. JavaScript belongs to the other category, called interpreted. In the case of JavaScript, this interpretation is done by the browser software at run-time. Because JavaScript is interpreted, this means that no special tools are required to write or edit JavaScript, just a normal text editor. JavaScript web pages can be platform independent i.e. they will run on different browsers and computers (as long as the browser is JavaScript enabled). If you see a JavaScript web page that you like, you may be able to take that JavaScript and use it for your own purposes. (Remember to acknowledge the original author!)
  6. Examples should be shown which demonstrate different uses of JavaScript. For example, try the calculator example at the address shown. JavaScript can provide interactivity and/or enhance pages in several ways. It is particularly good at manipulating browser elements and images to improve page presentation and navigation. As a programming language it can handle quite complex calculations and control the behaviour of embedded content including images. A useful function is input validation - checking form responses BEFORE the form is sent for processing to a server. In this way it can be quicker and more user friendly, providing immediate feedback to the user. JavaScript can be combined with other technologies such as Java applets or plug-ins, but this is beyond the scope of this presentation.
  7. JavaScript can be contained either in the header section of an HTML page or in the body. This JavaScript statement is shown as a pure JavaScript statement within SCRIPT tags. Notice that there is no HTML in the body of this page at all. (Demonstrate what this JavaScript looks like in a web browser). This statement writes a line of text on a web page. The command document.write is a standard function in JavaScript to write text to the page. The following is a more technical explanation for background information only: document.write is derived from the JavaScript object model (not covered in detail here). It works on the principle that all document and browser elements have an object name (document, window, image etc) and can each has various properties that can be manipulated. The object hierarchy means that individual elements can be uniquely identified i.e. document.myform.mytext would refer to the text entry named mytext within the form called myform within the current page (document). The arrow symbol &amp;apos;&amp;apos; is used in these slides and in the workbook to indicate where a JavaScript statement should be typed on one line without a break. A line break in the wrong place will stop JavaScript from working.e.g. document.write(&amp;apos;This is my first  JavaScript Page&amp;apos;); should actually be typed: document.write(&amp;apos;This is my first JavaScript Page&amp;apos;);
  8. This example demonstrates that anything included within the quotes in the document.write statement is printed to the screen, and this includes HTML tags. The &amp;lt;h1&amp;gt; tag is delivered to the browser along with the text, and the browser would interpret it as a normal HTML file, displaying the text in the Heading 1 style. IMPORTANT NOTE: This example shows a JavaScript statement in the &amp;lt;body&amp;gt; of the web page. It is possible to include JavaScript statements in the &amp;lt;head&amp;gt; section of a web page but care must be taken that they do not try to access items that don&amp;apos;t exist until the page has loaded (e.g. form elements, links, images). The web browser parses (reads through and executes) any script commands as it displays the page. In most cases it is common sense that dictates where a statement should be placed. If, in the above example, document.write was placed in the &amp;lt;head&amp;gt; of the page, the text &amp;quot;This is my first JavaScript Page&amp;quot; would appear in the &amp;lt;head&amp;gt; of the finished page – this would be incorrect – although modern browsers will let you get away with it! In some circumstances you may wish to use document.write in the &amp;lt;head&amp;gt; - for example to dynamically generate &amp;lt;meta&amp;gt; or &amp;lt;title&amp;gt; tags. Such uses are not considered here. JavaScript functions are typically defined in the &amp;lt;head&amp;gt; section of a web page as they do not normally execute until they have been triggered elsewhere. The use of functions in JavaScript is covered in the Netskills Training Module: &amp;quot;Further JavaScript (Enhancing JavaScript with Functions and Events)&amp;quot;
  9. Compare this example with the previous one. This time the JavaScript is written inside the HTML tags and there are no &amp;lt;script&amp;gt; tags. In this case if the browser is JavaScript-enabled it will process the commands when it needs to. If the browser doesn&amp;apos;t understand JavaScript it will ignore the extra code (it should see it as an HTML attribute that it cannot process and therefore ignores, although very old browsers my throw an error) This example demonstrates an HTML hyperlink, but notice the JavaScript enclosed within the &amp;lt;a href.. tag of the second link. onMouseOver is referring to an event. That is, this JavaScript will happen in response to something that the user does e.g click a button, or in this case, when they move the mouse over the link (this will not happen if you move your mouse over the first link!). window.alert will display what is called an alert box on the screen containing the text specified, in this case, &amp;quot;hello&amp;quot;. The first link will behave normally. (See separate Netskills Training Module for more details on Functions and Events in JavaScript.)
  10. This example shows two separate statements. The first is some pure JavaScript so must be contained within &amp;lt;script&amp;gt; tags. It displays a pop up box with the message &amp;quot;Enter your name&amp;quot; and a space to type in text. This occurs immediately when the page loads. The second statement is within an HTML form. The &amp;lt;input&amp;gt; tag includes some JavaScript within it. The tag creates a form element (a button) and associates with it some JavaScript. The JavaScript responds to the mouse click event (onClick) on the button by producing a pop up alert box with the text &amp;apos;Hello&amp;apos; in. This only occurs when the user triggers the event by clicking on the button. JavaScript makes use of both single and double quotes. They are used in this example to have a text string &amp;apos;Hello&amp;apos; contained within another string which defines the code to be carried out in response to the onClick event. It is important that the quotes should match - if they don&amp;apos;t, your JavaScript will not work!
  11. JavaScript is very useful for processing and manipulating user input and form elements. A common way of obtaining input is via the HTML &amp;lt;form&amp;gt; elements which can provide text entry boxes, selection boxes, menus and buttons. Form elements can be named and hence uniquely identified within the JavaScript object model.
  12. This example shows a simple form. Notice the name attribute is used at all points - to name the form, and to name each element within the form. How JavaScript uses the name attribute is described next.
  13. To refer to the value that a user has typed in a text box, you use the following naming system: document.formname.elementname.value This is a naming convention derived from the JavaScript object model: document refers to the page displayed in the browser. formname is supplied by the page author as the name attribute of the &amp;lt;form&amp;gt; tag - in the example it is addressform and refers to the whole form. elementname is supplied by the page author using the name attribute of the &amp;lt;input&amp;gt; tag. value is a predefined term which refers to the text typed in by the user.
  14. This simple code creates a form called alertform. The JavaScript is activated when &amp;apos;Go&amp;apos; button is pressed (an onClick event - see separate Netskills Training Module for more details on Functions and Events in JavaScript). The current value of the element yourname would be displayed in a an alert box.