SlideShare a Scribd company logo
1 of 49
JavaScript
Introduction
1
JavaScriptIntroduction
What is Java Script ?
• JavaScript is a client-side scripting language.
• A scripting language is a lightweight programming
language.
• JavaScript is programming code that can be inserted
into HTML pages.
• JavaScript inserted into HTML pages, can be
executed by all modern web browsers.
• Java Script can enhance the dynamics and
interactive features of your page by allowing you to
perform calculations, check forms, write interactive
games, add special effects, customize graphics
selections, create security passwords and more. 2
JavaScriptIntroduction
What is Java Script ?
• JavaScript is used in Web site development to such
things as:
 check or modify the contents of forms
 change images
 open new windows and write dynamic page content.
 to make DHTML by CSS.
 This allows you to make parts of your web pages
appear or disappear or move around on the page
3
JavaScriptIntroduction
Java Script Vs Java
JavaScript Java
Interpreted (not compiled)
by client.
Compiled on server before
execution on client.
Object-based. Code uses
built-in, extensible objects,
but no classes or inheritance.
Object-oriented. Applets
consist of object classes with
inheritance.
Code integrated with, and
embedded in, HTML.
Applets distinct from HTML
(accessed from HTML
pages).
Variable data types not
declared (loose typing).
Variable data types must be
declared (strong typing).
Secure. Cannot write to hard
disk.
Secure. Cannot write to hard
disk.
4
JavaScriptIntroduction
ECMA Script
• The responsibility for the development of a
scripting standard has been transferred to an
international body called the European
Computer Manufacturers Association
(ECMA).
• The standard developed by the ECMA is
called ECMAScript, though browsers still
refer to it as JavaScript.
• The latest version is ECMA-262, which is
supported by the major browsers. 5
JavaScriptIntroduction
Writing a Java Script Program
• The Web browser runs a JavaScript program
when the Web page is first loaded, or in
response to an event.
• JavaScript programs can either be placed
directly into the HTML file or they can be
saved in external files.
• placing a program in an external file allows
you to hide the program code from the user
• source code placed directly in the HTML
file can be viewed by anyone 6
JavaScriptIntroduction
Writing a Java Script Program
• A JavaScript program can be placed
anywhere within the HTML file.
• Many programmers favor placing their
programs between <head> tags in order to
separate the programming code from the
Web page content and layout.
• Some programmers prefer placing programs
within the <Body> of the Web page at the
location where the program output is
generated and displayed.
7
JavaScriptIntroduction
How to use/implement Java Script?
• We can implement Java script in our web
page by following three ways-
1. Inside the head tag
2. Within the body tag
3. In an external file (with extension .js)
8
JavaScriptIntroduction
Implementing Java Script
1. Inside HEAD Tag:
Syntax:
<HTML>
<HEAD>
<SCRIPT TYPE= “TEXT/JAVASCRIPT”>
<!- -
Java Script Code
// - ->
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML> 9
JavaScriptIntroduction
Implementing Java Script
2. Within BODY Tag:
Syntax:
<HTML>
<HEAD>
</HEAD>
<BODY>
<SCRIPT TYPE= “TEXT/JAVASCRIPT”>
<!- -
java script code
// - ->
</SCRIPT>
</BODY>
</HTML> 10
JavaScriptIntroduction
Implementing Java Script
3. In an External Link:
Syntax:
<HTML>
<HEAD>
<SCRIPT SRC= “myscript.js”>
</SCRIPT>
</HEAD>
<BODY>
<input TYPE=“Button” onclick=“msg()” value=“Message”>
</BODY>
</HTML>
Myscript.js:
Function msg()
{ alert("Hello") } 11
JavaScriptIntroduction
Java Script Syntax Issue
• JavaScript commands and names are case
sensitive.
• JavaScript command lines end with a
semicolon to separate it from the next
command line in the program.
• in some situations, the semicolon is
optional
• semicolons are useful to make your code
easier to follow and interpret
12
JavaScriptIntroduction
Displaying some text on web Page
• You can write on page by using following
statement of Java script-
document.write(“message”)
document.writeln(“message”)
Example:
document.write(“<h1><B>My first message</B></h1>” ) ;
13
JavaScriptIntroduction
JavaScript Display Possibilities
• JavaScript does NOT have any built-in print or
display functions.
• JavaScript can "display" data in different ways:
• Writing into an alert box, using window.alert().
• Writing into the HTML output
using document.write().
• Writing into an HTML element,
using innerHTML.
• Writing into the browser console,
using console.log().
14
JavaScriptIntroduction
window.alert()
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>
window.alert(5 + 6);
</script>
</body></html>
15
JavaScriptIntroduction
16
JavaScriptIntroduction
document.write()
<html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<button type="button"
onclick="document.write(5 + 6)">
Try it</button>
</body>
</html>
17
JavaScriptIntroduction
18
JavaScriptIntroduction
innerHTML
<html> <body>
<h1>My First Web Page</h1>
<p>My First Paragraph.</p>
<p id="demo"></p>
<script>
document.getElementById("demo")
.innerHTML = 5 + 6;
</script>
</body>
</html> 19
JavaScriptIntroduction
20
JavaScriptIntroduction
console.log()
<!DOCTYPE html>
<html><body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<p> Activate debugging in your browser (Chrome, IE,
Firefox) with F12, and select "Console" in the debugger
menu. </p>
<script> console.log(5 + 6);
</script>
</body>
</html> 21
JavaScriptIntroduction
22
JavaScriptIntroduction
Working with Variables & Data
• A variable is a named element in a program
that stores information.
var var_name;
• The following restrictions apply to variable
names:
• the first character must be either a letter or an
underscore character ( _ )
• the remaining characters can be letters, numbers,
or underscore characters
• variable names cannot contain spaces
• Variable names are case-sensitive.
23
JavaScriptIntroduction
Types of Variables
• JavaScript supports four different types
of variables
•Numeric variables can be a number, such
as 13, 22.5, or -3.14159
•string variables is any group of characters,
such as “Hello” or “Happy Holidays!”
•Boolean variables are variables that accept
one of two values, either true or false
•null variables is a variable that has no value
at all 24
JavaScriptIntroduction
Declaring/Creating a Variable
• Before you can use a variable in your
program, you need to declare a variable
using the var command or by assigning the
variable a value.
• Any of the following commands is a
legitimate way of creating a variable named
“Month”:
var Month;
Month = “December”;
var Month = “December”; 25
JavaScriptIntroduction
Operators in JavaScript
• Following operators are used in
JavaScript-
1. Arithmetic Operator
2. Comparison Operator
26
JavaScriptIntroduction
Operators in JavaScript
• Following operators are used in JavaScript-
1. Arithmetic Operator
Operator Meaning Example
+ Addition 2 + 4
- Subtraction 6 - 2
* Multiplication 5 * 3
/ Division 15 / 3
% Modulus 43 % 10
27
JavaScriptIntroduction
Example
<body>
<script
type="text/JavaScript">
<!–
var two = 2
var ten = 10
var linebreak = "<br />"
document.write("two plus ten =
")
var result = two + ten
document.write(result)
document.write(linebreak)
document.write("ten * ten = ")
result = ten * ten
document.write(result)
document.write(linebreak)
document.write("ten / two = ")
result = ten / two
document.write(result)
//-->
</script>
</body>
28
JavaScriptIntroduction
Output
two plus ten = 12
ten * ten = 100
ten / two = 5
29
JavaScriptIntroduction
Operators in JavaScript
2. Comparison Operator
Operator Meaning Example Result
== Equal To x == y false
=== Equal value and equal
type
x===y true
!= Not Equal To x != y true
!== not equal value or not
equal type
x!== false
< Less Than x < y true
> Greater Than x > y false
<= Less Than or Equal To x <= y true
>= Greater Than or Equal To x >= y false 30
JavaScriptIntroduction
Built-in JavaScript Functions
• Functions provided by the language and you cannot
change them to suit your needs.
• Some of the built-in functions in JavaScript are
shown here:
• eval - eval(expr)
• eval evaluates the expression or statements
• isFinite
• Determines if a number is finite
• isNaN
• Determines whether a value is “Not a Number”
• parseInt
• Converts string literals to integers, no number  NaN.
• parseFloat
• Finds a floating-point value at the beginning of a string.
31
JavaScriptIntroduction
JavaScript Functions
• A function is a block of organized reusable
code (a set of statements) for performing a
single or related action.
• Begins with keyword “function” and the
function name and “( … )”
• Inside the parentheses
• We can pass parameters to the function
• E.g. function myfuc(arg1, arg2) {…}
• Built-in and user-defined functions
32
JavaScriptIntroduction
Creating JavaScript Functions
Declaration Syntax
• Functions are declared using the function
reserved word
• The return value is not declared, nor are the
types of the arguments
function function_name(parameters) {
JavaScript commands
}
• parameters are the values sent to the function
(note: not all functions require parameters)
• { and } are used to mark the beginning and end of
the commands in the function. 33
JavaScriptIntroduction
Creating JavaScript Functions: Eg
<HTML>
<HEAD>
<SCRIPT TYPE=TEXT/JAVASCRIPT>
<!- -
function myMessage()
{
document.write(“<B>Hello World”);
}
// - ->
</SCRIPT>
</HEAD>
<BODY>
<INPUT TYPE=BUTTON onClick=myMessage() Value=Click >
</BODY>
</HTML> 34
JavaScriptIntroduction
Event in JavaScript
• JavaScript is its ability to help you create dynamic web
pages that increase user interaction
• The building blocks of an interactive web page is the
JavaScript event system.
• An event in JavaScript is something that happens with
or on the webpage.
• A few example of events:
• A mouse click
• The webpage loading
• Mousing over a hot spot on the webpage, also known as hovering
• Selecting an input box in an HTML form
• A keystroke 35
JavaScriptIntroduction
Event in JavaScript
• JS Event Handler
• Onclick
• onMouseOver
• onMouseOut
• onLoad
• onkeydown
36
JavaScriptIntroduction
JavaScript Object
• Object
• Number
• String
• Date
• Array
• Boolean
• Math, etc
37
JavaScriptIntroduction
What is the DOM?
• The DOM is a W3C (World Wide Web Consortium)
standard.
• The DOM defines a standard for accessing documents:
"The W3C Document Object Model (DOM) is a platform
and language-neutral interface that allows programs and
scripts to dynamically access and update the content,
structure, and style of a document."
• The W3C DOM standard is separated into 3 different
parts:
• Core DOM - standard model for all document types
• XML DOM - standard model for XML documents
• HTML DOM - standard model for HTML documents
JavaScriptIntroduction
38
What is the HTML DOM?
• The HTML DOM is a standard object model and
programming interface for HTML.
• It defines:
• The HTML elements as objects
• The properties of all HTML elements
• The methods to access all HTML elements
• The events for all HTML elements
• In other words:
The HTML DOM is a standard for how to get,
change, add, or delete HTML elements.
JavaScriptIntroduction
39
• When a web page is loaded, the browser creates a Document
Object Model of the page.
• The HTML DOM model is constructed as a tree of Objects:
JavaScriptIntroduction
40
What is the HTML DOM?
• With the object model, JavaScript gets all the power it
needs to create dynamic HTML:
• JavaScript can change all the HTML elements in the
page
• JavaScript can change all the HTML attributes in the
page
• JavaScript can change all the CSS styles in the page
• JavaScript can remove existing HTML elements and
attributes
• JavaScript can add new HTML elements and attributes
• JavaScript can react to all existing HTML events in the
page
• JavaScript can create new HTML events in the page
JavaScriptIntroduction
41
The HTML DOM Document
• HTML DOM object model, the document object
represents your web page.
• The document object is the owner of all other objects in
your web page.
• If you want to access objects in an HTML page, you
always start with accessing the document object.
JavaScriptIntroduction
42
Finding HTML Elements
JavaScriptIntroduction
43
Method Description
document.getElementById() Find an element by element id
document.getElementsByTagName() Find elements by tag name
document.getElementsByClassName(
)
Find elements by class name
Changing HTML Elements
JavaScriptIntroduction
44
Method Description
element.innerHTML= Change the inner HTML of an element
element.attribute= Change the attribute of an HTML element
element.setAttribute(attribute,
value)
Change the attribute of an HTML element
element.style.property= Change the style of an HTML element
Adding and Deleting Elements
JavaScriptIntroduction
45
Method Description
document.createElement() Create an HTML element
document.removeChild() Remove an HTML element
document.appendChild() Add an HTML element
document.replaceChild() Replace an HTML element
document.write(text) Write into the HTML output stream
Adding Events Handlers
JavaScriptIntroduction
46
Method Description
document.getElementById(id).
onclick=function()
{code}
Adding event handler code to an onclick
event
Document Object
• Java script enable browsers are capable of recognizing
individual objects in a HTML page.
• Each HTML document loaded into a browser window
becomes a Document object.
• The Document object provides access to all HTML elements
in a page, from within a script.
• DOM has following properties-
• Anchor
• Applet
• Body
• Cookies
• Form
• Image
• Link
• Title
• URL , etc
47
JavaScriptIntroduction
Validation in JavaScript
48
JavaScriptIntroduction
<!DOCTYPE html><html><body>
<h1>JavaScript Can Validate Input</h1>
<p>Please input a number between 1 and 10:</p>
<input id="numb" type="number">
<button type="button" onclick="myFunction()">Submit</button>
<p id="demo"></p>
<script>
function myFunction() {
var x, text;
// Get the value of the input field with id="numb"
x = document.getElementById("numb").value;
// If x is Not a Number or less than one or greater than 10
if (isNaN(x) || x < 1 || x > 10) {
text = "Input not valid";
} else {
text = "Input OK";
}
document.getElementById("demo").innerHTML = text;
}
</script></body></html>
JavaScriptIntroduction
49

More Related Content

What's hot

Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScriptBala Narayanan
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentationAdhoura Academy
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypesVarun C M
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSSAmit Tyagi
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
 
Javascript
JavascriptJavascript
JavascriptNagarajan
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...Edureka!
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and FunctionsJussi Pohjolainen
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptFahim Abdullah
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - OperatorsWebStackAcademy
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSSMario Hernandez
 
cascading style sheet ppt
cascading style sheet pptcascading style sheet ppt
cascading style sheet pptabhilashagupta
 

What's hot (20)

Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
CSS
CSSCSS
CSS
 
Css selectors
Css selectorsCss selectors
Css selectors
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
 
Javascript
JavascriptJavascript
Javascript
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java Script
 
Html coding
Html codingHtml coding
Html coding
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - Operators
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
 
cascading style sheet ppt
cascading style sheet pptcascading style sheet ppt
cascading style sheet ppt
 
jQuery
jQueryjQuery
jQuery
 
Javascript
JavascriptJavascript
Javascript
 

Similar to Java script

Iwt note(module 2)
Iwt note(module 2)Iwt note(module 2)
Iwt note(module 2)SANTOSH RATH
 
MTA understanding java script and coding essentials
MTA understanding java script and coding essentialsMTA understanding java script and coding essentials
MTA understanding java script and coding essentialsDhairya Joshi
 
Final Java-script.pptx
Final Java-script.pptxFinal Java-script.pptx
Final Java-script.pptxAlkanthiSomesh
 
3. Java Script
3. Java Script3. Java Script
3. Java ScriptJalpesh Vasa
 
JS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTINGJS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTINGArulkumar
 
Basic Java script handouts for students
Basic Java script handouts for students Basic Java script handouts for students
Basic Java script handouts for students shafiq sangi
 
Client sidescripting javascript
Client sidescripting javascriptClient sidescripting javascript
Client sidescripting javascriptSelvin Josy Bai Somu
 
8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentation8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentationJohnLagman3
 
Javascript - Ebook (A Quick Guide)
Javascript - Ebook (A Quick Guide)Javascript - Ebook (A Quick Guide)
Javascript - Ebook (A Quick Guide)sourav newatia
 
Introduction to JavaScript Programming
Introduction to JavaScript ProgrammingIntroduction to JavaScript Programming
Introduction to JavaScript ProgrammingRaveendra R
 
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.pdfAAFREEN SHAIKH
 
Java script by Act Academy
Java script by Act AcademyJava script by Act Academy
Java script by Act Academyactanimation
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scriptsch samaram
 
JavaScripts & jQuery
JavaScripts & jQueryJavaScripts & jQuery
JavaScripts & jQueryAsanka Indrajith
 
javascript 1
javascript 1javascript 1
javascript 1osman do
 
WT Unit-3 PPT.pptx
WT Unit-3 PPT.pptxWT Unit-3 PPT.pptx
WT Unit-3 PPT.pptxTusharTikia
 
Thinkful - Intro to JavaScript
Thinkful - Intro to JavaScriptThinkful - Intro to JavaScript
Thinkful - Intro to JavaScriptTJ Stalcup
 
Session vii(java scriptbasics)
Session vii(java scriptbasics)Session vii(java scriptbasics)
Session vii(java scriptbasics)Shrijan Tiwari
 

Similar to Java script (20)

Iwt note(module 2)
Iwt note(module 2)Iwt note(module 2)
Iwt note(module 2)
 
MTA understanding java script and coding essentials
MTA understanding java script and coding essentialsMTA understanding java script and coding essentials
MTA understanding java script and coding essentials
 
Final Java-script.pptx
Final Java-script.pptxFinal Java-script.pptx
Final Java-script.pptx
 
3. Java Script
3. Java Script3. Java Script
3. Java Script
 
JS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTINGJS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTING
 
Basic Java script handouts for students
Basic Java script handouts for students Basic Java script handouts for students
Basic Java script handouts for students
 
Client sidescripting javascript
Client sidescripting javascriptClient sidescripting javascript
Client sidescripting javascript
 
8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentation8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentation
 
Javascript - Ebook (A Quick Guide)
Javascript - Ebook (A Quick Guide)Javascript - Ebook (A Quick Guide)
Javascript - Ebook (A Quick Guide)
 
Introduction to JavaScript Programming
Introduction to JavaScript ProgrammingIntroduction to JavaScript Programming
Introduction to JavaScript Programming
 
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
 
Java script by Act Academy
Java script by Act AcademyJava script by Act Academy
Java script by Act Academy
 
Welcome to React.pptx
Welcome to React.pptxWelcome to React.pptx
Welcome to React.pptx
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
 
IP Unit 2.pptx
IP Unit 2.pptxIP Unit 2.pptx
IP Unit 2.pptx
 
JavaScripts & jQuery
JavaScripts & jQueryJavaScripts & jQuery
JavaScripts & jQuery
 
javascript 1
javascript 1javascript 1
javascript 1
 
WT Unit-3 PPT.pptx
WT Unit-3 PPT.pptxWT Unit-3 PPT.pptx
WT Unit-3 PPT.pptx
 
Thinkful - Intro to JavaScript
Thinkful - Intro to JavaScriptThinkful - Intro to JavaScript
Thinkful - Intro to JavaScript
 
Session vii(java scriptbasics)
Session vii(java scriptbasics)Session vii(java scriptbasics)
Session vii(java scriptbasics)
 

Recently uploaded

Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Study on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube ExchangerAnamika Sarkar
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 

Recently uploaded (20)

young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Study on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned ďťżTube Exchanger
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 

Java script

  • 2. What is Java Script ? • JavaScript is a client-side scripting language. • A scripting language is a lightweight programming language. • JavaScript is programming code that can be inserted into HTML pages. • JavaScript inserted into HTML pages, can be executed by all modern web browsers. • Java Script can enhance the dynamics and interactive features of your page by allowing you to perform calculations, check forms, write interactive games, add special effects, customize graphics selections, create security passwords and more. 2 JavaScriptIntroduction
  • 3. What is Java Script ? • JavaScript is used in Web site development to such things as:  check or modify the contents of forms  change images  open new windows and write dynamic page content.  to make DHTML by CSS.  This allows you to make parts of your web pages appear or disappear or move around on the page 3 JavaScriptIntroduction
  • 4. Java Script Vs Java JavaScript Java Interpreted (not compiled) by client. Compiled on server before execution on client. Object-based. Code uses built-in, extensible objects, but no classes or inheritance. Object-oriented. Applets consist of object classes with inheritance. Code integrated with, and embedded in, HTML. Applets distinct from HTML (accessed from HTML pages). Variable data types not declared (loose typing). Variable data types must be declared (strong typing). Secure. Cannot write to hard disk. Secure. Cannot write to hard disk. 4 JavaScriptIntroduction
  • 5. ECMA Script • The responsibility for the development of a scripting standard has been transferred to an international body called the European Computer Manufacturers Association (ECMA). • The standard developed by the ECMA is called ECMAScript, though browsers still refer to it as JavaScript. • The latest version is ECMA-262, which is supported by the major browsers. 5 JavaScriptIntroduction
  • 6. Writing a Java Script Program • The Web browser runs a JavaScript program when the Web page is first loaded, or in response to an event. • JavaScript programs can either be placed directly into the HTML file or they can be saved in external files. • placing a program in an external file allows you to hide the program code from the user • source code placed directly in the HTML file can be viewed by anyone 6 JavaScriptIntroduction
  • 7. Writing a Java Script Program • A JavaScript program can be placed anywhere within the HTML file. • Many programmers favor placing their programs between <head> tags in order to separate the programming code from the Web page content and layout. • Some programmers prefer placing programs within the <Body> of the Web page at the location where the program output is generated and displayed. 7 JavaScriptIntroduction
  • 8. How to use/implement Java Script? • We can implement Java script in our web page by following three ways- 1. Inside the head tag 2. Within the body tag 3. In an external file (with extension .js) 8 JavaScriptIntroduction
  • 9. Implementing Java Script 1. Inside HEAD Tag: Syntax: <HTML> <HEAD> <SCRIPT TYPE= “TEXT/JAVASCRIPT”> <!- - Java Script Code // - -> </SCRIPT> </HEAD> <BODY> </BODY> </HTML> 9 JavaScriptIntroduction
  • 10. Implementing Java Script 2. Within BODY Tag: Syntax: <HTML> <HEAD> </HEAD> <BODY> <SCRIPT TYPE= “TEXT/JAVASCRIPT”> <!- - java script code // - -> </SCRIPT> </BODY> </HTML> 10 JavaScriptIntroduction
  • 11. Implementing Java Script 3. In an External Link: Syntax: <HTML> <HEAD> <SCRIPT SRC= “myscript.js”> </SCRIPT> </HEAD> <BODY> <input TYPE=“Button” onclick=“msg()” value=“Message”> </BODY> </HTML> Myscript.js: Function msg() { alert("Hello") } 11 JavaScriptIntroduction
  • 12. Java Script Syntax Issue • JavaScript commands and names are case sensitive. • JavaScript command lines end with a semicolon to separate it from the next command line in the program. • in some situations, the semicolon is optional • semicolons are useful to make your code easier to follow and interpret 12 JavaScriptIntroduction
  • 13. Displaying some text on web Page • You can write on page by using following statement of Java script- document.write(“message”) document.writeln(“message”) Example: document.write(“<h1><B>My first message</B></h1>” ) ; 13 JavaScriptIntroduction
  • 14. JavaScript Display Possibilities • JavaScript does NOT have any built-in print or display functions. • JavaScript can "display" data in different ways: • Writing into an alert box, using window.alert(). • Writing into the HTML output using document.write(). • Writing into an HTML element, using innerHTML. • Writing into the browser console, using console.log(). 14 JavaScriptIntroduction
  • 15. window.alert() <!DOCTYPE html> <html> <body> <h1>My First Web Page</h1> <p>My first paragraph.</p> <script> window.alert(5 + 6); </script> </body></html> 15 JavaScriptIntroduction
  • 17. document.write() <html> <body> <h1>My First Web Page</h1> <p>My first paragraph.</p> <button type="button" onclick="document.write(5 + 6)"> Try it</button> </body> </html> 17 JavaScriptIntroduction
  • 19. innerHTML <html> <body> <h1>My First Web Page</h1> <p>My First Paragraph.</p> <p id="demo"></p> <script> document.getElementById("demo") .innerHTML = 5 + 6; </script> </body> </html> 19 JavaScriptIntroduction
  • 21. console.log() <!DOCTYPE html> <html><body> <h1>My First Web Page</h1> <p>My first paragraph.</p> <p> Activate debugging in your browser (Chrome, IE, Firefox) with F12, and select "Console" in the debugger menu. </p> <script> console.log(5 + 6); </script> </body> </html> 21 JavaScriptIntroduction
  • 23. Working with Variables & Data • A variable is a named element in a program that stores information. var var_name; • The following restrictions apply to variable names: • the first character must be either a letter or an underscore character ( _ ) • the remaining characters can be letters, numbers, or underscore characters • variable names cannot contain spaces • Variable names are case-sensitive. 23 JavaScriptIntroduction
  • 24. Types of Variables • JavaScript supports four different types of variables •Numeric variables can be a number, such as 13, 22.5, or -3.14159 •string variables is any group of characters, such as “Hello” or “Happy Holidays!” •Boolean variables are variables that accept one of two values, either true or false •null variables is a variable that has no value at all 24 JavaScriptIntroduction
  • 25. Declaring/Creating a Variable • Before you can use a variable in your program, you need to declare a variable using the var command or by assigning the variable a value. • Any of the following commands is a legitimate way of creating a variable named “Month”: var Month; Month = “December”; var Month = “December”; 25 JavaScriptIntroduction
  • 26. Operators in JavaScript • Following operators are used in JavaScript- 1. Arithmetic Operator 2. Comparison Operator 26 JavaScriptIntroduction
  • 27. Operators in JavaScript • Following operators are used in JavaScript- 1. Arithmetic Operator Operator Meaning Example + Addition 2 + 4 - Subtraction 6 - 2 * Multiplication 5 * 3 / Division 15 / 3 % Modulus 43 % 10 27 JavaScriptIntroduction
  • 28. Example <body> <script type="text/JavaScript"> <!– var two = 2 var ten = 10 var linebreak = "<br />" document.write("two plus ten = ") var result = two + ten document.write(result) document.write(linebreak) document.write("ten * ten = ") result = ten * ten document.write(result) document.write(linebreak) document.write("ten / two = ") result = ten / two document.write(result) //--> </script> </body> 28 JavaScriptIntroduction
  • 29. Output two plus ten = 12 ten * ten = 100 ten / two = 5 29 JavaScriptIntroduction
  • 30. Operators in JavaScript 2. Comparison Operator Operator Meaning Example Result == Equal To x == y false === Equal value and equal type x===y true != Not Equal To x != y true !== not equal value or not equal type x!== false < Less Than x < y true > Greater Than x > y false <= Less Than or Equal To x <= y true >= Greater Than or Equal To x >= y false 30 JavaScriptIntroduction
  • 31. Built-in JavaScript Functions • Functions provided by the language and you cannot change them to suit your needs. • Some of the built-in functions in JavaScript are shown here: • eval - eval(expr) • eval evaluates the expression or statements • isFinite • Determines if a number is finite • isNaN • Determines whether a value is “Not a Number” • parseInt • Converts string literals to integers, no number  NaN. • parseFloat • Finds a floating-point value at the beginning of a string. 31 JavaScriptIntroduction
  • 32. JavaScript Functions • A function is a block of organized reusable code (a set of statements) for performing a single or related action. • Begins with keyword “function” and the function name and “( … )” • Inside the parentheses • We can pass parameters to the function • E.g. function myfuc(arg1, arg2) {…} • Built-in and user-defined functions 32 JavaScriptIntroduction
  • 33. Creating JavaScript Functions Declaration Syntax • Functions are declared using the function reserved word • The return value is not declared, nor are the types of the arguments function function_name(parameters) { JavaScript commands } • parameters are the values sent to the function (note: not all functions require parameters) • { and } are used to mark the beginning and end of the commands in the function. 33 JavaScriptIntroduction
  • 34. Creating JavaScript Functions: Eg <HTML> <HEAD> <SCRIPT TYPE=TEXT/JAVASCRIPT> <!- - function myMessage() { document.write(“<B>Hello World”); } // - -> </SCRIPT> </HEAD> <BODY> <INPUT TYPE=BUTTON onClick=myMessage() Value=Click > </BODY> </HTML> 34 JavaScriptIntroduction
  • 35. Event in JavaScript • JavaScript is its ability to help you create dynamic web pages that increase user interaction • The building blocks of an interactive web page is the JavaScript event system. • An event in JavaScript is something that happens with or on the webpage. • A few example of events: • A mouse click • The webpage loading • Mousing over a hot spot on the webpage, also known as hovering • Selecting an input box in an HTML form • A keystroke 35 JavaScriptIntroduction
  • 36. Event in JavaScript • JS Event Handler • Onclick • onMouseOver • onMouseOut • onLoad • onkeydown 36 JavaScriptIntroduction
  • 37. JavaScript Object • Object • Number • String • Date • Array • Boolean • Math, etc 37 JavaScriptIntroduction
  • 38. What is the DOM? • The DOM is a W3C (World Wide Web Consortium) standard. • The DOM defines a standard for accessing documents: "The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document." • The W3C DOM standard is separated into 3 different parts: • Core DOM - standard model for all document types • XML DOM - standard model for XML documents • HTML DOM - standard model for HTML documents JavaScriptIntroduction 38
  • 39. What is the HTML DOM? • The HTML DOM is a standard object model and programming interface for HTML. • It defines: • The HTML elements as objects • The properties of all HTML elements • The methods to access all HTML elements • The events for all HTML elements • In other words: The HTML DOM is a standard for how to get, change, add, or delete HTML elements. JavaScriptIntroduction 39
  • 40. • When a web page is loaded, the browser creates a Document Object Model of the page. • The HTML DOM model is constructed as a tree of Objects: JavaScriptIntroduction 40 What is the HTML DOM?
  • 41. • With the object model, JavaScript gets all the power it needs to create dynamic HTML: • JavaScript can change all the HTML elements in the page • JavaScript can change all the HTML attributes in the page • JavaScript can change all the CSS styles in the page • JavaScript can remove existing HTML elements and attributes • JavaScript can add new HTML elements and attributes • JavaScript can react to all existing HTML events in the page • JavaScript can create new HTML events in the page JavaScriptIntroduction 41
  • 42. The HTML DOM Document • HTML DOM object model, the document object represents your web page. • The document object is the owner of all other objects in your web page. • If you want to access objects in an HTML page, you always start with accessing the document object. JavaScriptIntroduction 42
  • 43. Finding HTML Elements JavaScriptIntroduction 43 Method Description document.getElementById() Find an element by element id document.getElementsByTagName() Find elements by tag name document.getElementsByClassName( ) Find elements by class name
  • 44. Changing HTML Elements JavaScriptIntroduction 44 Method Description element.innerHTML= Change the inner HTML of an element element.attribute= Change the attribute of an HTML element element.setAttribute(attribute, value) Change the attribute of an HTML element element.style.property= Change the style of an HTML element
  • 45. Adding and Deleting Elements JavaScriptIntroduction 45 Method Description document.createElement() Create an HTML element document.removeChild() Remove an HTML element document.appendChild() Add an HTML element document.replaceChild() Replace an HTML element document.write(text) Write into the HTML output stream
  • 46. Adding Events Handlers JavaScriptIntroduction 46 Method Description document.getElementById(id). onclick=function() {code} Adding event handler code to an onclick event
  • 47. Document Object • Java script enable browsers are capable of recognizing individual objects in a HTML page. • Each HTML document loaded into a browser window becomes a Document object. • The Document object provides access to all HTML elements in a page, from within a script. • DOM has following properties- • Anchor • Applet • Body • Cookies • Form • Image • Link • Title • URL , etc 47 JavaScriptIntroduction
  • 48. Validation in JavaScript 48 JavaScriptIntroduction <!DOCTYPE html><html><body> <h1>JavaScript Can Validate Input</h1> <p>Please input a number between 1 and 10:</p> <input id="numb" type="number"> <button type="button" onclick="myFunction()">Submit</button> <p id="demo"></p> <script> function myFunction() { var x, text; // Get the value of the input field with id="numb" x = document.getElementById("numb").value; // If x is Not a Number or less than one or greater than 10 if (isNaN(x) || x < 1 || x > 10) { text = "Input not valid"; } else { text = "Input OK"; } document.getElementById("demo").innerHTML = text; } </script></body></html>