SlideShare a Scribd company logo
1 of 40
JavaScript Basics
Presented by : Manisha Chugh
Batch Code: B-14/PHP/04-01
Registration id: R13010624
What is JavaScript?
• JavaScript is a scripting language designed for Web
pages.
• It enhances Web pages with dynamic and interactive
features.
• It enables shopping carts, form validation,
calculations, special graphic and text effects, image
swapping and more.
©Copyright 2014 by Manisha All Rights
Reserved.
Methods of Using
JavaScript
1. External - JavaScript can reside in a separate page.
2. Internal - JavaScript can be embedded in HTML
documents -- in the <head>, in the <body>, or in both.
3. Inline - JavaScript object attributes can be placed in
HTML element tags.
©Copyright 2014 by Manisha All Rights
Reserved.
External JavaScript
• Linking can be advantageous if many pages use the
same script.
• Use the source element to link to the script file.
<script src="myjavascript.js”
type="text/javascript">
</script>
©Copyright 2014 by Manisha All Rights
Reserved.
Internal JavaScript
• When specifying a script only the tags <script>
and </script> are essential, but complete
specification is recommended:
<script language="javascript”
type="text/javascript">
<!-- Begin hiding
window.location=”index.html"
// End hiding script-->
</script>
©Copyright 2014 by Manisha All Rights
Reserved.
Using Comment Tags
• HTML comment tags should bracket any script.
• The <!-- script here --> tags hide scripts in
HTML and prevent scripts from displaying in browsers
that do not interpret JavaScript.
• Double slashes // are the signal characters for a
JavaScript single-line comment.
©Copyright 2014 by Manisha All Rights
Reserved.
Inline JavaScript
• Event handlers like onLoad are a perfect example of
an easy to add tag script.
e.g.
<body onLoad="alert('WELCOME')">
©Copyright 2014 by Manisha All Rights
Reserved.
JavaScript Terminology
• Objects,
• Properties,
• Functions,
• Methods,
• Events,
• Listeners,
• Variables.
©Copyright 2014 by Manisha All Rights
Reserved.
Objects
• Objects refers to windows, documents, images,
tables, forms, buttons or links, etc.
• Objects should be named.
• Objects have properties that act as modifiers.
©Copyright 2014 by Manisha All Rights
Reserved.
Properties
• Properties are object attributes.
• Object properties are defined by using the object's
name, a period, and the property name.
• e.g., background color is expressed by:
document.bgcolor.
Here, document is the object.
bgcolor is the property.
©Copyright 2014 by Manisha All Rights
Reserved.
Functions
• A group of statements that is put together once and
then can be used repeatedly on a Web page.
• JavaScript has built-in functions, and you can write
your own.
©Copyright 2014 by Manisha All Rights
Reserved.
Format of a function
definition
function function-name( parameter-list )
{
declarations and statements
}
Here,
• Function name is any valid identifier.
• Parameter list contains names of variables that will receive
arguments.
• Declarations and statements are function body (“block” of
code)
©Copyright 2014 by Manisha All Rights
Reserved.
Methods
• Methods are functions.
• They are unusual in the sense that they are stored as
properties of objects.
• e.g., document.write(”Hello World")
Here, document is the object.
write is the method.
©Copyright 2014 by Manisha All Rights
Reserved.
Events
• Events are visitor’s and browser’s activities.
• There can be two types of events:
• User-Initiated Events
• Browser-Initiated Events
©Copyright 2014 by Manisha All Rights
Reserved.
Browser-Initiated Events
• load
• unload
• error
• abort
©Copyright 2014 by Manisha All Rights
Reserved.
User-Initiated Events
• click
• dblclick
• keydown
• keyup
• keypress
• mouseover
• mouseout
• mousedown
• mouseup
• mousemove
• change
• resize
• scroll
• select
• blur
• focus
• submit
©Copyright 2014 by Manisha All Rights
Reserved.
Listeners
• Listeners capture and actually respond to those
events. Thus, they are also known as Event
Handlers.
• The system sends events to the listener program and
the program responds to them as they arrive.
©Copyright 2014 by Manisha All Rights
Reserved.
Listeners (Cont.)
• Events handlers are placed in the BODY part of a Web page as
attributes in HTML tags.
e.g.
<input type=button name=btn1 value=“Click
Me” onClick=“alert(‘button was
clicked’);”>
• Alternatively, events can be captured in the HTML code, and then
directed to a JavaScript function for an appropriate response.
©Copyright 2014 by Manisha All Rights
Reserved.
Listeners (Cont.)
e.g.
<head>
<script language= "JavaScript"
type="text/javascript">
function mymessage()
{
alert(“Hello User!");
}
</script>
</head>
<body onload="mymessage()">
</body>
©Copyright 2014 by Manisha All Rights
Reserved.
Various Event Handlers
• The following event handlers are available in
JavaScript:
• onAbort
• onBlur
• onChange
• onClick
• onDragDrop
• onError
• onFocus
• onKeyDown
• onKeyPress
• onKeyUp
• onSubmit
• onMouseDown
• onMouseMove
• onMouseOut
• onMouseOver
• onMouseUp
• onResize
• onSelect
• onSubmit
• onLoad
• onUnload
©Copyright 2014 by Manisha All Rights
Reserved.
Various Event Handlers
(Cont.)
• onAbort
An abort event occurs when a user aborts the loading of an image
(for example by clicking a link or clicking the Stop button).
• onBlur
A blur event occurs when object on a form loses focus.
• onChange
A change event occurs when any object (select, text, or textarea)
loses focus and its value has been modified.
• onClick
A click event occurs when an object on a form is clicked.
©Copyright 2014 by Manisha All Rights
Reserved.
Various Event Handlers
(Cont.)
• onDragDrop
A drapDrop event occurs when a user drops an object onto the browser
window, such as dropping a file.
• onError
An error event occurs when the loading of a document or image causes an
error.
• onFocus
A focus event occurs when a field receives input focus by tabbing with the
keyboard or clicking with the mouse.
• onKeyDown, onKeyPress, onKeyUp
A keyDown, keyPress, or keyUp event occurs when a user depresses a key,
presses or holds down a key, or releases a key, respectively.
©Copyright 2014 by Manisha All Rights
Reserved.
Various Event Handlers
(Cont.)
• onMouseDown, onMouseMove, onMouseOut,
onMouseOver, and onMouseUp
A MouseDown, MouseMove, MouseOut, MouseOver, or MouseUp
event occurs when a user depresses a mouse button, moves a cursor,
moves a cursor out of the object, moves a cursor over the object,
releases a mouse button, respectively.
• onResize
A Resize event occurs when a user or script resizes a window.
©Copyright 2014 by Manisha All Rights
Reserved.
Various Event Handlers
(Cont.)
• onSelect
A select event occurs when a user selects some of the text within a text or
textarea field.
• onSubmit
A submit event occurs when a user submits a form.
• onLoad
A load event occurs after a web page is loaded.
• onUnload
An unload event occurs when you exit a web page.
©Copyright 2014 by Manisha All Rights
Reserved.
Event Handlers and the
“this” Keyword
• ‘This’ keyword is used for self-reference of object when an
event handler calls a JavaScript function.
e.g.
<input type="button" value="press me" onclick
= "callfunc(this);">
// Here ‘this’ keyword refers to the Button
object.
©Copyright 2014 by Manisha All Rights
Reserved.
Variables
• Variables contain values and use the equal sign to specify
their value.
• Variables are created by declaration using the var
command with or without an initial value state.
• e.g. var month;
• e.g. var month = April;
©Copyright 2014 by Manisha All Rights
Reserved.
Dialog Boxes
• Dialog boxes can be used to –
• inform the user of errors or events
• confirm actions initiated by the user
• ask some information from the user
©Copyright 2014 by Manisha All Rights
Reserved.
Alert Dialog Box
• Alert Dialog Box informs the user about errors or events.
User can just read the message and press OK.
e.g.
alert(‘Hello! Welcome to my website.');
©Copyright 2014 by Manisha All Rights
Reserved.
Confirm Dialog Box
• Confirm Dialog Box confirms actions initiated by the
user. User can confirm or Cancel the action.
e.g.
confirm('Are you sure you want to exit?');
©Copyright 2014 by Manisha All Rights
Reserved.
Prompt Dialog Box
• Prompt Dialog Box is used to get information from the
user.
e.g.
prompt('Enter your name:');
©Copyright 2014 by Manisha All Rights
Reserved.
Accessing HTML Elements
In JavaScript
• In JavaScript, you can access specific HTML elements by
using a pre-defined variable called document and requesting
the element by ID.
• Accessing an HTML element by ID, general syntax:
document.getElementById("<ID>")
e.g.
document.getElementById(“d1”).innerHTML=“Hello
World!”;
<div id=“d1”></div>
©Copyright 2014 by Manisha All Rights
Reserved.
Accessing HTML Elements
In JavaScript (Cont.)
• Once you have access to a particular HTML element, you can
access all its attributes using the "dot" operator.
• Accessing an element's attribute, general syntax:
document.getElementById("<ID>").<attribute>
• Accessing form element, general syntax:
document.formname.elementname.value
©Copyright 2014 by Manisha All Rights
Reserved.
Example
<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>
©Copyright 2014 by Manisha All Rights
Reserved.
Accessing CSS Properties
• Accessing CSS properties, general syntax:
document.getElementById("<ID>").style.<property>
• Property names in JavaScript are identical to those in CSS, but
with namesLikeThis instead of names-like-this
e.g.
backgroundColor instead of background-color
• Example:
document.getElementById("name").style.backgroundColor =
"yellow";
©Copyright 2014 by Manisha All Rights
Reserved.
Form Validations
• JavaScript is very good at processing and validating user input
in the web browser.
• Requirements to perform validations:
• Form’s name must be specified.
• Object’s name must be specified.
• Input must be of Submit type.
• Validations can be applied in two ways:
1. Traditional iterative programming methodologies
2. Pattern matching (via regular expressions)
©Copyright 2014 by Manisha All Rights
Reserved.
Traditional iterative
programming methodologies
• Write a small program (function) that iterates
through the user input and validates the data type
and returns true or false depending on result.
• This can be relatively slow, especially if form has
many fields to be validated.
©Copyright 2014 by Manisha All Rights
Reserved.
Example
function validate()
{
if(document.login.uname.value==“”)
{
alert(“Please enter username”);
document.login.uname.focus();
return false;
}
return true;
}
<form name=“login” action=“” onsubmit=“validate()”>
<input type=“text” name=“uname”>
©Copyright 2014 by Manisha All Rights
Reserved.
Pattern matching
• Create a regular expression pattern for the data type
and let the system validate the user input via its
pattern matching capabilities.
• Pattern matching is very quick (even for long
forms).
©Copyright 2014 by Manisha All Rights
Reserved.
HTML5 Validation
• required
<input type=“text” name=“uname” required/>
• pattern= ‘a regular expression’ like text, search,
url, telephone, email, and password.
<input type=“email” name=“email”/>
• min= max = step= can be used with <input type=range>
<input type=“range” max=“30”>
©Copyright 2014 by Manisha All Rights
Reserved.
Thank You!

More Related Content

What's hot

Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
Adhoura Academy
 

What's hot (20)

JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging Techniques
 
Print function in PHP
Print function in PHPPrint function in PHP
Print function in PHP
 
7. check box control
7. check box control7. check box control
7. check box control
 
Java script
Java scriptJava script
Java script
 
JavaScript Lecture notes.pptx
JavaScript Lecture notes.pptxJavaScript Lecture notes.pptx
JavaScript Lecture notes.pptx
 
JavaScript Functions
JavaScript Functions JavaScript Functions
JavaScript Functions
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Awt, Swing, Layout managers
Awt, Swing, Layout managersAwt, Swing, Layout managers
Awt, Swing, Layout managers
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and Statements
 
Css3
Css3Css3
Css3
 
Java socket programming
Java socket programmingJava socket programming
Java socket programming
 
DOM and Events
DOM and EventsDOM and Events
DOM and Events
 
Session tracking in servlets
Session tracking in servletsSession tracking in servlets
Session tracking in servlets
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
 
HTML5: features with examples
HTML5: features with examplesHTML5: features with examples
HTML5: features with examples
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 

Viewers also liked

01 Introduction - JavaScript Development
01 Introduction - JavaScript Development01 Introduction - JavaScript Development
01 Introduction - JavaScript Development
Tommy Vercety
 
An Introduction to JavaScript: Week One
An Introduction to JavaScript: Week OneAn Introduction to JavaScript: Week One
An Introduction to JavaScript: Week One
Event Handler
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
tonyh1
 
introduction to javascript
introduction to javascriptintroduction to javascript
introduction to javascript
Kumar
 

Viewers also liked (17)

JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
 
JavaScript Introduction
JavaScript IntroductionJavaScript Introduction
JavaScript Introduction
 
01 Introduction - JavaScript Development
01 Introduction - JavaScript Development01 Introduction - JavaScript Development
01 Introduction - JavaScript Development
 
An Introduction to JavaScript: Week One
An Introduction to JavaScript: Week OneAn Introduction to JavaScript: Week One
An Introduction to JavaScript: Week One
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
 
JavaScript Introduction
JavaScript IntroductionJavaScript Introduction
JavaScript Introduction
 
Front-end development introduction (JavaScript). Part 2
Front-end development introduction (JavaScript). Part 2Front-end development introduction (JavaScript). Part 2
Front-end development introduction (JavaScript). Part 2
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
introduction to javascript
introduction to javascriptintroduction to javascript
introduction to javascript
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Java script
Java scriptJava script
Java script
 
Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
 
Reactive Programming with JavaScript
Reactive Programming with JavaScriptReactive Programming with JavaScript
Reactive Programming with JavaScript
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
JavaScript code academy - introduction
JavaScript code academy - introductionJavaScript code academy - introduction
JavaScript code academy - introduction
 

Similar to Learn Javascript Basics

Java Script basics and DOM
Java Script basics and DOMJava Script basics and DOM
Java Script basics and DOM
Sukrit Gupta
 
JAVASCRIPT 1.pptx.pptx
JAVASCRIPT 1.pptx.pptxJAVASCRIPT 1.pptx.pptx
JAVASCRIPT 1.pptx.pptx
BeingPrime
 

Similar to Learn Javascript Basics (20)

Javascript 2
Javascript 2Javascript 2
Javascript 2
 
Java Script basics and DOM
Java Script basics and DOMJava Script basics and DOM
Java Script basics and DOM
 
JavaScript
JavaScriptJavaScript
JavaScript
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Hsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdfHsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdf
 
JavaScript_introduction_upload.pdf
JavaScript_introduction_upload.pdfJavaScript_introduction_upload.pdf
JavaScript_introduction_upload.pdf
 
Java script
Java scriptJava script
Java script
 
Java script
Java scriptJava script
Java script
 
JAVASCRIPT 1.pptx.pptx
JAVASCRIPT 1.pptx.pptxJAVASCRIPT 1.pptx.pptx
JAVASCRIPT 1.pptx.pptx
 
CHAPTER 3 JS (1).pptx
CHAPTER 3  JS (1).pptxCHAPTER 3  JS (1).pptx
CHAPTER 3 JS (1).pptx
 
JavaScript Introduction
JavaScript IntroductionJavaScript Introduction
JavaScript Introduction
 
Unit 4(it workshop)
Unit 4(it workshop)Unit 4(it workshop)
Unit 4(it workshop)
 
WP - Unit I.ppt
WP - Unit I.pptWP - Unit I.ppt
WP - Unit I.ppt
 
JS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTINGJS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTING
 
Javascript
JavascriptJavascript
Javascript
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
 
Building interactive app
Building interactive appBuilding interactive app
Building interactive app
 
JavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & Implementation
 
javascript 1
javascript 1javascript 1
javascript 1
 
Introduction to HTML language Web design.pptx
Introduction to HTML language Web design.pptxIntroduction to HTML language Web design.pptx
Introduction to HTML language Web design.pptx
 

Recently uploaded

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
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
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
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Recently uploaded (20)

PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
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
 
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
 
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
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
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
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

Learn Javascript Basics

  • 1. JavaScript Basics Presented by : Manisha Chugh Batch Code: B-14/PHP/04-01 Registration id: R13010624
  • 2. What is JavaScript? • JavaScript is a scripting language designed for Web pages. • It enhances Web pages with dynamic and interactive features. • It enables shopping carts, form validation, calculations, special graphic and text effects, image swapping and more. ©Copyright 2014 by Manisha All Rights Reserved.
  • 3. Methods of Using JavaScript 1. External - JavaScript can reside in a separate page. 2. Internal - JavaScript can be embedded in HTML documents -- in the <head>, in the <body>, or in both. 3. Inline - JavaScript object attributes can be placed in HTML element tags. ©Copyright 2014 by Manisha All Rights Reserved.
  • 4. External JavaScript • Linking can be advantageous if many pages use the same script. • Use the source element to link to the script file. <script src="myjavascript.js” type="text/javascript"> </script> ©Copyright 2014 by Manisha All Rights Reserved.
  • 5. Internal JavaScript • When specifying a script only the tags <script> and </script> are essential, but complete specification is recommended: <script language="javascript” type="text/javascript"> <!-- Begin hiding window.location=”index.html" // End hiding script--> </script> ©Copyright 2014 by Manisha All Rights Reserved.
  • 6. Using Comment Tags • HTML comment tags should bracket any script. • The <!-- script here --> tags hide scripts in HTML and prevent scripts from displaying in browsers that do not interpret JavaScript. • Double slashes // are the signal characters for a JavaScript single-line comment. ©Copyright 2014 by Manisha All Rights Reserved.
  • 7. Inline JavaScript • Event handlers like onLoad are a perfect example of an easy to add tag script. e.g. <body onLoad="alert('WELCOME')"> ©Copyright 2014 by Manisha All Rights Reserved.
  • 8. JavaScript Terminology • Objects, • Properties, • Functions, • Methods, • Events, • Listeners, • Variables. ©Copyright 2014 by Manisha All Rights Reserved.
  • 9. Objects • Objects refers to windows, documents, images, tables, forms, buttons or links, etc. • Objects should be named. • Objects have properties that act as modifiers. ©Copyright 2014 by Manisha All Rights Reserved.
  • 10. Properties • Properties are object attributes. • Object properties are defined by using the object's name, a period, and the property name. • e.g., background color is expressed by: document.bgcolor. Here, document is the object. bgcolor is the property. ©Copyright 2014 by Manisha All Rights Reserved.
  • 11. Functions • A group of statements that is put together once and then can be used repeatedly on a Web page. • JavaScript has built-in functions, and you can write your own. ©Copyright 2014 by Manisha All Rights Reserved.
  • 12. Format of a function definition function function-name( parameter-list ) { declarations and statements } Here, • Function name is any valid identifier. • Parameter list contains names of variables that will receive arguments. • Declarations and statements are function body (“block” of code) ©Copyright 2014 by Manisha All Rights Reserved.
  • 13. Methods • Methods are functions. • They are unusual in the sense that they are stored as properties of objects. • e.g., document.write(”Hello World") Here, document is the object. write is the method. ©Copyright 2014 by Manisha All Rights Reserved.
  • 14. Events • Events are visitor’s and browser’s activities. • There can be two types of events: • User-Initiated Events • Browser-Initiated Events ©Copyright 2014 by Manisha All Rights Reserved.
  • 15. Browser-Initiated Events • load • unload • error • abort ©Copyright 2014 by Manisha All Rights Reserved.
  • 16. User-Initiated Events • click • dblclick • keydown • keyup • keypress • mouseover • mouseout • mousedown • mouseup • mousemove • change • resize • scroll • select • blur • focus • submit ©Copyright 2014 by Manisha All Rights Reserved.
  • 17. Listeners • Listeners capture and actually respond to those events. Thus, they are also known as Event Handlers. • The system sends events to the listener program and the program responds to them as they arrive. ©Copyright 2014 by Manisha All Rights Reserved.
  • 18. Listeners (Cont.) • Events handlers are placed in the BODY part of a Web page as attributes in HTML tags. e.g. <input type=button name=btn1 value=“Click Me” onClick=“alert(‘button was clicked’);”> • Alternatively, events can be captured in the HTML code, and then directed to a JavaScript function for an appropriate response. ©Copyright 2014 by Manisha All Rights Reserved.
  • 19. Listeners (Cont.) e.g. <head> <script language= "JavaScript" type="text/javascript"> function mymessage() { alert(“Hello User!"); } </script> </head> <body onload="mymessage()"> </body> ©Copyright 2014 by Manisha All Rights Reserved.
  • 20. Various Event Handlers • The following event handlers are available in JavaScript: • onAbort • onBlur • onChange • onClick • onDragDrop • onError • onFocus • onKeyDown • onKeyPress • onKeyUp • onSubmit • onMouseDown • onMouseMove • onMouseOut • onMouseOver • onMouseUp • onResize • onSelect • onSubmit • onLoad • onUnload ©Copyright 2014 by Manisha All Rights Reserved.
  • 21. Various Event Handlers (Cont.) • onAbort An abort event occurs when a user aborts the loading of an image (for example by clicking a link or clicking the Stop button). • onBlur A blur event occurs when object on a form loses focus. • onChange A change event occurs when any object (select, text, or textarea) loses focus and its value has been modified. • onClick A click event occurs when an object on a form is clicked. ©Copyright 2014 by Manisha All Rights Reserved.
  • 22. Various Event Handlers (Cont.) • onDragDrop A drapDrop event occurs when a user drops an object onto the browser window, such as dropping a file. • onError An error event occurs when the loading of a document or image causes an error. • onFocus A focus event occurs when a field receives input focus by tabbing with the keyboard or clicking with the mouse. • onKeyDown, onKeyPress, onKeyUp A keyDown, keyPress, or keyUp event occurs when a user depresses a key, presses or holds down a key, or releases a key, respectively. ©Copyright 2014 by Manisha All Rights Reserved.
  • 23. Various Event Handlers (Cont.) • onMouseDown, onMouseMove, onMouseOut, onMouseOver, and onMouseUp A MouseDown, MouseMove, MouseOut, MouseOver, or MouseUp event occurs when a user depresses a mouse button, moves a cursor, moves a cursor out of the object, moves a cursor over the object, releases a mouse button, respectively. • onResize A Resize event occurs when a user or script resizes a window. ©Copyright 2014 by Manisha All Rights Reserved.
  • 24. Various Event Handlers (Cont.) • onSelect A select event occurs when a user selects some of the text within a text or textarea field. • onSubmit A submit event occurs when a user submits a form. • onLoad A load event occurs after a web page is loaded. • onUnload An unload event occurs when you exit a web page. ©Copyright 2014 by Manisha All Rights Reserved.
  • 25. Event Handlers and the “this” Keyword • ‘This’ keyword is used for self-reference of object when an event handler calls a JavaScript function. e.g. <input type="button" value="press me" onclick = "callfunc(this);"> // Here ‘this’ keyword refers to the Button object. ©Copyright 2014 by Manisha All Rights Reserved.
  • 26. Variables • Variables contain values and use the equal sign to specify their value. • Variables are created by declaration using the var command with or without an initial value state. • e.g. var month; • e.g. var month = April; ©Copyright 2014 by Manisha All Rights Reserved.
  • 27. Dialog Boxes • Dialog boxes can be used to – • inform the user of errors or events • confirm actions initiated by the user • ask some information from the user ©Copyright 2014 by Manisha All Rights Reserved.
  • 28. Alert Dialog Box • Alert Dialog Box informs the user about errors or events. User can just read the message and press OK. e.g. alert(‘Hello! Welcome to my website.'); ©Copyright 2014 by Manisha All Rights Reserved.
  • 29. Confirm Dialog Box • Confirm Dialog Box confirms actions initiated by the user. User can confirm or Cancel the action. e.g. confirm('Are you sure you want to exit?'); ©Copyright 2014 by Manisha All Rights Reserved.
  • 30. Prompt Dialog Box • Prompt Dialog Box is used to get information from the user. e.g. prompt('Enter your name:'); ©Copyright 2014 by Manisha All Rights Reserved.
  • 31. Accessing HTML Elements In JavaScript • In JavaScript, you can access specific HTML elements by using a pre-defined variable called document and requesting the element by ID. • Accessing an HTML element by ID, general syntax: document.getElementById("<ID>") e.g. document.getElementById(“d1”).innerHTML=“Hello World!”; <div id=“d1”></div> ©Copyright 2014 by Manisha All Rights Reserved.
  • 32. Accessing HTML Elements In JavaScript (Cont.) • Once you have access to a particular HTML element, you can access all its attributes using the "dot" operator. • Accessing an element's attribute, general syntax: document.getElementById("<ID>").<attribute> • Accessing form element, general syntax: document.formname.elementname.value ©Copyright 2014 by Manisha All Rights Reserved.
  • 33. Example <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> ©Copyright 2014 by Manisha All Rights Reserved.
  • 34. Accessing CSS Properties • Accessing CSS properties, general syntax: document.getElementById("<ID>").style.<property> • Property names in JavaScript are identical to those in CSS, but with namesLikeThis instead of names-like-this e.g. backgroundColor instead of background-color • Example: document.getElementById("name").style.backgroundColor = "yellow"; ©Copyright 2014 by Manisha All Rights Reserved.
  • 35. Form Validations • JavaScript is very good at processing and validating user input in the web browser. • Requirements to perform validations: • Form’s name must be specified. • Object’s name must be specified. • Input must be of Submit type. • Validations can be applied in two ways: 1. Traditional iterative programming methodologies 2. Pattern matching (via regular expressions) ©Copyright 2014 by Manisha All Rights Reserved.
  • 36. Traditional iterative programming methodologies • Write a small program (function) that iterates through the user input and validates the data type and returns true or false depending on result. • This can be relatively slow, especially if form has many fields to be validated. ©Copyright 2014 by Manisha All Rights Reserved.
  • 37. Example function validate() { if(document.login.uname.value==“”) { alert(“Please enter username”); document.login.uname.focus(); return false; } return true; } <form name=“login” action=“” onsubmit=“validate()”> <input type=“text” name=“uname”> ©Copyright 2014 by Manisha All Rights Reserved.
  • 38. Pattern matching • Create a regular expression pattern for the data type and let the system validate the user input via its pattern matching capabilities. • Pattern matching is very quick (even for long forms). ©Copyright 2014 by Manisha All Rights Reserved.
  • 39. HTML5 Validation • required <input type=“text” name=“uname” required/> • pattern= ‘a regular expression’ like text, search, url, telephone, email, and password. <input type=“email” name=“email”/> • min= max = step= can be used with <input type=range> <input type=“range” max=“30”> ©Copyright 2014 by Manisha All Rights Reserved.