SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Introduction
 JavaScript is the most popular programming language in the
world.
 JavaScript is the programming language of the Web.
 Was designed to add interactivity to HTML pages.
 All modern HTML pages are using JavaScript.
 One of scripting language.
 Supported by most the browsers
IE, Firefox, Chrome, Opera, Safari and Netscape Navigator.
Introduction
 Embedded directly in HTML pages.
 Java and JavaScript are two different languages.
 Java can stand on its own.
 JavaScript must be placed inside an HTML document to
function.
 JavaScript is Case-sensitive.
Purpose
 JavaScript Can Change HTML Content
 JavaScript Can Change HTML Attributes
 JavaScript Can Change HTML Styles (CSS)
 JavaScript Can Validate Data
 JavaScript Can display different pop-ups
Javascript in HTML
 <script> tag is used to insert a JavaScript into an HTML
page.
Example:
<script>
document.getElementById("demo").innerHTML = "My First JavaScript";
</script>
 Scripts in the body section
 Scripts in the head section
 Scripts in both the body section and head section
External JavaScript
 External scripts are practical when the same code is used in
many different web pages.
 External scripts cannot contain <script> tags.
 Save it with a .js file extension.
“ xxx.js”
 Call script "src" attribute, from any of your html pages
<script src="xxx.js">
 Advantages:
 It separates HTML and code.
 It makes HTML and JavaScript easier to read and maintain.
 Cached JavaScript files can speed up page loads.
JavaScript Output
 Writing into an alert box, using window.alert().
<script> window.alert(5 + 6); </script>
 Writing into the HTML output using document.write().
<script> document.write(5 + 6); </script>
 Writing into an HTML element, using innerHTML.
<script>
document.getElementById("demo").innerHTML = 5+ 6;
</script>
 Writing into the browser console, using console.log().
<script> console.log(5 + 6); </script>
JavaScript Comments
 Single line comment: start the line with two slashes "//":
sum=a + b //calculating the sum
 Multi line comment: "/*" and "*/"
/* This is a comment block. It contains several lines*/
JavaScript Variables
 To store data values
 Rules for Variable names:
Variable names are case sensitive
Names can contain letters, digits, underscores, and
dollar signs
They must begin with a letter ,the $ character or the
underscore character
JavaScript keywords cannot be used as names
Declaration: var x;
var name;
Assign value to variable: x=5;
name=“FTD” or ‘FTD’;
JavaScript Variables
 Declare & Assign variables :
var x=5;
var name=“FTD” or ‘FTD’;
 One Statement, Many Variables :
var x=5, name=“FTD” or ‘FTD’;
 Local variables
 Global variables
 Lifetime of JavaScript local & global Variables
JavaScript Data Types
 JavaScript variables can hold many data types.
 String, Number, Boolean, Array, Object and more.
 Used to be able to operate on variables.
 Examples:
var length = 16; // Number
var lastName = "Johnson"; // String
var cars = [“Skoda", "Volvo", "BMW"]; // Array
var x = {firstName:"John", lastName:"Doe"}; // Object
var z= true; //Boolean
JavaScript Data Types
 If the one operand is a string, JavaScript will also treat the
other operand as a string.
var x = 16 + "Volvo";
 JavaScript evaluates expressions from left to right.
var x = 16 + 4 + "Volvo";
var x = "Volvo" + 16 + 4;
 JavaScript has dynamic types. The same variable can be used
as different types
var x = 5; // Now x is a Number
var x = "John"; // Now x is a String
JavaScript Operators
 Arithmetic +, -, *, /, %, --, ++
 Assignment =, -=, +=,*=, /=
 Logical &&, ||, !
 Comparison ==, !=, >, <, <=, >=,
Ternary operator(a<b)?A=10:A=5
“===“equal value and equal type
“!==“not equal value or not equal type
above both compares both value and type, like below…
123=“123”
Functions
 Function- is a block of code designed to perform a particular task and is
executed when
 When an event occurs (when a user clicks a button)
 When it is invoked (called) from JavaScript code
 Automatically (self invoked)
 Define the code once, and use it many times
 Same code many times with different arguments, to produce different results.
 Defining function
function function_name(arguments)
{
statements;
}
Return statement
return(“text”);
Conditional stmts
 In JavaScript we have three conditional statements:
if statement
if...else statement
if …else if… else statement
Syntax:
if (condition1) {
block of code to be executed if condition1 is true
} else if (condition2) {
block of code to be executed if the condition1 is false and condition2 is true
} else {
block of code to be executed if the condition1 is false and condition2 is false
}
Switch stmts
 Statement is used to perform different action based on different
conditions.
Syntax:
switch(expression) {
case n:
code n block
break;
case m:
code m block
break;
default:
default code block
}
Looping stmts
 Loops can execute a block of code a number of times.
 In JavaScript we have the following looping statements:
 while
Syntax:
while (condition) {
code block to be executed
}
Looping stmts
 do-while
Syntax:
do {
code block to be executed
}
while (condition);
 for
Syntax:
for (statement 1; statement 2; statement 3) {
code block to be executed
}
Arrays
 Arrays are used to store multiple values in a single variable.
 Array creation :
1. var team=new Array();
team[0]=“FTD";
team[1]=“Mercury";
2. var team=new Array(“FTD",“Mercury");
3. var team=[“ftd",“Mercury“];
 Access an Array: we can access array elements by using name of
the array and index value.
 Array methods : length, sort and etc …
Events
 Events are actions.
Examples of events:
1. A mouse click
2. Submitting an HTML form
3.A keystroke
 <body> and <frameset> Events
 Form Events
 Image Events
 Keyboard Events
 Mouse Events
Methods
 Methods:
onLoad and onUnload
onFocus and onChange
onSubmit
onMouseOver
onclick
Popup Boxes
 We can create three kinds of popup boxes:
 Alert Box: information is displayed to the user.
Syntax: alert("sometext");
 Confirm box: user to verify or accept something.
Syntax: confirm("sometext")
 Prompt Box: user to input a value before entering a
page.
Syntax: prompt("sometext","defaultvalue")
Form validations
 JavaScript can be used to validate input data in HTML
forms before sending off the content to a server.
 verify Required Fields using JavaScript
 verify Email using JavaScript
References
 Java Script
 http://www.w3schools.com/JS/default.asp
 http://www.tutorialspoint.com/javascript/javascript_q
uick_guide.htm
Assignments
 Write a JavaScript program to get the website URL (loading
page)?
 Write a JavaScript program to display the title of current page?
 Write a JavaScript program to get the current date in
"dd/mm/yyyy" format?
 Write a JavaScript program to find the area of a triangle where
lengths of the three of its sides are 5, 6, 7
 Write a JavaScript program to calculate multiplication and
division of two numbers using functions(input from user).
Assignments
Assignment #1: Add field validations for HTML assignment #1 (Create an Employee Information Page)
The following fields should be mandatory, appropriate error message should display if the field is left blank or entered with
invalid data.
• Name field : Accept only alphabets and Max 20 characters.
• DOB (DD/MM/YYYY)
• What do you do Section
• Team Members text area
• Mailing Address
• Permanent Address
• Email ID field
Submit button : On clicking the ‘Submit’ button
• Display message: “Thank you. Your details are submitted successfully”, if valid data is entered in all the fields
• Display field level error message for each field, if invalid data is entered or filed is left blank.
Clear button: On clicking the ‘Clear’ button
• Entered data should be cleared for all the fields.
Assignment #2: Add field validations for HTML assignment #2 (Create a webpage as below with
your information)
The following fields should be mandatory, appropriate error message should display if the field is left blank or entered
with invalid data.
• Name: Accept only alphabets and Max 40 characters.
• Email: Accept alphabet, special characters & numbers, characters should present before and after @ symbol,
end with .com/.org/.in
• Gender ( radio button)
• County( Drop down list)
• Get back to me via: Email , Phone, Personally ( Check boxes)
• Comments: Text area of a fixed size.
Submit button : On clicking the ‘Submit’ button
• Display message: “Thank you. Your details are submitted successfully”, if valid data is entered in all the fields
• Display field level error message for each field, if invalid data is entered or filed is left blank.

Weitere ähnliche Inhalte

Was ist angesagt?

CSS3 2D/3D transform
CSS3 2D/3D transformCSS3 2D/3D transform
CSS3 2D/3D transform
Kenny Lee
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 

Was ist angesagt? (20)

Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
Java script
Java scriptJava script
Java script
 
CSS3 2D/3D transform
CSS3 2D/3D transformCSS3 2D/3D transform
CSS3 2D/3D transform
 
Dom(document object model)
Dom(document object model)Dom(document object model)
Dom(document object model)
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
CSS
CSSCSS
CSS
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
HTML5: features with examples
HTML5: features with examplesHTML5: features with examples
HTML5: features with examples
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arrays
 
Java script
Java scriptJava script
Java script
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
Javascript
JavascriptJavascript
Javascript
 

Andere mochten auch

Css margin and padding property
Css margin and padding propertyCss margin and padding property
Css margin and padding property
Jesus Obenita Jr.
 

Andere mochten auch (11)

Smarter Interfaces with jQuery (and Drupal)
Smarter Interfaces with jQuery (and Drupal)Smarter Interfaces with jQuery (and Drupal)
Smarter Interfaces with jQuery (and Drupal)
 
Yahoo presentation: JavaScript Events
Yahoo presentation: JavaScript EventsYahoo presentation: JavaScript Events
Yahoo presentation: JavaScript Events
 
WP HTTP API
WP HTTP APIWP HTTP API
WP HTTP API
 
Css margin and padding property
Css margin and padding propertyCss margin and padding property
Css margin and padding property
 
Jquery Example PPT
Jquery Example PPTJquery Example PPT
Jquery Example PPT
 
JavaScript Introduction
JavaScript IntroductionJavaScript Introduction
JavaScript Introduction
 
Cours php bac info
Cours php bac infoCours php bac info
Cours php bac info
 
Introduction to WordPress
Introduction to WordPressIntroduction to WordPress
Introduction to WordPress
 
Jquery validate - TuanNA
Jquery validate - TuanNAJquery validate - TuanNA
Jquery validate - TuanNA
 
HTML5 & WAI-ARIA Forms with jQuery Validation
HTML5 & WAI-ARIA Forms with jQuery ValidationHTML5 & WAI-ARIA Forms with jQuery Validation
HTML5 & WAI-ARIA Forms with jQuery Validation
 
Search Analytics for Content Strategists
Search Analytics for Content StrategistsSearch Analytics for Content Strategists
Search Analytics for Content Strategists
 

Ähnlich wie Javascript

Java script
 Java script Java script
Java script
bosybosy
 
Advisor Jumpstart: JavaScript
Advisor Jumpstart: JavaScriptAdvisor Jumpstart: JavaScript
Advisor Jumpstart: JavaScript
dominion
 
wp-UNIT_III.pptx
wp-UNIT_III.pptxwp-UNIT_III.pptx
wp-UNIT_III.pptx
GANDHAMKUMAR2
 
JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery Fundamentals
BG Java EE Course
 

Ähnlich wie Javascript (20)

Web programming
Web programmingWeb programming
Web programming
 
Java script
 Java script Java script
Java script
 
Java script
Java scriptJava script
Java script
 
BITM3730 10-17.pptx
BITM3730 10-17.pptxBITM3730 10-17.pptx
BITM3730 10-17.pptx
 
Web designing unit 4
Web designing unit 4Web designing unit 4
Web designing unit 4
 
Scripting languages
Scripting languagesScripting languages
Scripting languages
 
Advisor Jumpstart: JavaScript
Advisor Jumpstart: JavaScriptAdvisor Jumpstart: JavaScript
Advisor Jumpstart: JavaScript
 
Javascript
JavascriptJavascript
Javascript
 
Introduction to Javascript programming
Introduction to Javascript programmingIntroduction to Javascript programming
Introduction to Javascript programming
 
IT2255 Web Essentials - Unit III Client-Side Processing and Scripting
IT2255 Web Essentials - Unit III Client-Side Processing and ScriptingIT2255 Web Essentials - Unit III Client-Side Processing and Scripting
IT2255 Web Essentials - Unit III Client-Side Processing and Scripting
 
Final Java-script.pptx
Final Java-script.pptxFinal Java-script.pptx
Final Java-script.pptx
 
Javascript
JavascriptJavascript
Javascript
 
1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentals
 
wp-UNIT_III.pptx
wp-UNIT_III.pptxwp-UNIT_III.pptx
wp-UNIT_III.pptx
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
 
Client sidescripting javascript
Client sidescripting javascriptClient sidescripting javascript
Client sidescripting javascript
 
FSJavaScript.ppt
FSJavaScript.pptFSJavaScript.ppt
FSJavaScript.ppt
 
JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery Fundamentals
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 

Kürzlich hochgeladen

Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
UK Journal
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 

Kürzlich hochgeladen (20)

Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 

Javascript

  • 1.
  • 2. Introduction  JavaScript is the most popular programming language in the world.  JavaScript is the programming language of the Web.  Was designed to add interactivity to HTML pages.  All modern HTML pages are using JavaScript.  One of scripting language.  Supported by most the browsers IE, Firefox, Chrome, Opera, Safari and Netscape Navigator.
  • 3. Introduction  Embedded directly in HTML pages.  Java and JavaScript are two different languages.  Java can stand on its own.  JavaScript must be placed inside an HTML document to function.  JavaScript is Case-sensitive.
  • 4. Purpose  JavaScript Can Change HTML Content  JavaScript Can Change HTML Attributes  JavaScript Can Change HTML Styles (CSS)  JavaScript Can Validate Data  JavaScript Can display different pop-ups
  • 5. Javascript in HTML  <script> tag is used to insert a JavaScript into an HTML page. Example: <script> document.getElementById("demo").innerHTML = "My First JavaScript"; </script>  Scripts in the body section  Scripts in the head section  Scripts in both the body section and head section
  • 6. External JavaScript  External scripts are practical when the same code is used in many different web pages.  External scripts cannot contain <script> tags.  Save it with a .js file extension. “ xxx.js”  Call script "src" attribute, from any of your html pages <script src="xxx.js">  Advantages:  It separates HTML and code.  It makes HTML and JavaScript easier to read and maintain.  Cached JavaScript files can speed up page loads.
  • 7. JavaScript Output  Writing into an alert box, using window.alert(). <script> window.alert(5 + 6); </script>  Writing into the HTML output using document.write(). <script> document.write(5 + 6); </script>  Writing into an HTML element, using innerHTML. <script> document.getElementById("demo").innerHTML = 5+ 6; </script>  Writing into the browser console, using console.log(). <script> console.log(5 + 6); </script>
  • 8. JavaScript Comments  Single line comment: start the line with two slashes "//": sum=a + b //calculating the sum  Multi line comment: "/*" and "*/" /* This is a comment block. It contains several lines*/
  • 9. JavaScript Variables  To store data values  Rules for Variable names: Variable names are case sensitive Names can contain letters, digits, underscores, and dollar signs They must begin with a letter ,the $ character or the underscore character JavaScript keywords cannot be used as names Declaration: var x; var name; Assign value to variable: x=5; name=“FTD” or ‘FTD’;
  • 10. JavaScript Variables  Declare & Assign variables : var x=5; var name=“FTD” or ‘FTD’;  One Statement, Many Variables : var x=5, name=“FTD” or ‘FTD’;  Local variables  Global variables  Lifetime of JavaScript local & global Variables
  • 11. JavaScript Data Types  JavaScript variables can hold many data types.  String, Number, Boolean, Array, Object and more.  Used to be able to operate on variables.  Examples: var length = 16; // Number var lastName = "Johnson"; // String var cars = [“Skoda", "Volvo", "BMW"]; // Array var x = {firstName:"John", lastName:"Doe"}; // Object var z= true; //Boolean
  • 12. JavaScript Data Types  If the one operand is a string, JavaScript will also treat the other operand as a string. var x = 16 + "Volvo";  JavaScript evaluates expressions from left to right. var x = 16 + 4 + "Volvo"; var x = "Volvo" + 16 + 4;  JavaScript has dynamic types. The same variable can be used as different types var x = 5; // Now x is a Number var x = "John"; // Now x is a String
  • 13. JavaScript Operators  Arithmetic +, -, *, /, %, --, ++  Assignment =, -=, +=,*=, /=  Logical &&, ||, !  Comparison ==, !=, >, <, <=, >=, Ternary operator(a<b)?A=10:A=5 “===“equal value and equal type “!==“not equal value or not equal type above both compares both value and type, like below… 123=“123”
  • 14. Functions  Function- is a block of code designed to perform a particular task and is executed when  When an event occurs (when a user clicks a button)  When it is invoked (called) from JavaScript code  Automatically (self invoked)  Define the code once, and use it many times  Same code many times with different arguments, to produce different results.  Defining function function function_name(arguments) { statements; } Return statement return(“text”);
  • 15. Conditional stmts  In JavaScript we have three conditional statements: if statement if...else statement if …else if… else statement Syntax: if (condition1) { block of code to be executed if condition1 is true } else if (condition2) { block of code to be executed if the condition1 is false and condition2 is true } else { block of code to be executed if the condition1 is false and condition2 is false }
  • 16. Switch stmts  Statement is used to perform different action based on different conditions. Syntax: switch(expression) { case n: code n block break; case m: code m block break; default: default code block }
  • 17. Looping stmts  Loops can execute a block of code a number of times.  In JavaScript we have the following looping statements:  while Syntax: while (condition) { code block to be executed }
  • 18. Looping stmts  do-while Syntax: do { code block to be executed } while (condition);  for Syntax: for (statement 1; statement 2; statement 3) { code block to be executed }
  • 19. Arrays  Arrays are used to store multiple values in a single variable.  Array creation : 1. var team=new Array(); team[0]=“FTD"; team[1]=“Mercury"; 2. var team=new Array(“FTD",“Mercury"); 3. var team=[“ftd",“Mercury“];  Access an Array: we can access array elements by using name of the array and index value.  Array methods : length, sort and etc …
  • 20. Events  Events are actions. Examples of events: 1. A mouse click 2. Submitting an HTML form 3.A keystroke  <body> and <frameset> Events  Form Events  Image Events  Keyboard Events  Mouse Events
  • 21. Methods  Methods: onLoad and onUnload onFocus and onChange onSubmit onMouseOver onclick
  • 22. Popup Boxes  We can create three kinds of popup boxes:  Alert Box: information is displayed to the user. Syntax: alert("sometext");  Confirm box: user to verify or accept something. Syntax: confirm("sometext")  Prompt Box: user to input a value before entering a page. Syntax: prompt("sometext","defaultvalue")
  • 23. Form validations  JavaScript can be used to validate input data in HTML forms before sending off the content to a server.  verify Required Fields using JavaScript  verify Email using JavaScript
  • 24. References  Java Script  http://www.w3schools.com/JS/default.asp  http://www.tutorialspoint.com/javascript/javascript_q uick_guide.htm
  • 25.
  • 26. Assignments  Write a JavaScript program to get the website URL (loading page)?  Write a JavaScript program to display the title of current page?  Write a JavaScript program to get the current date in "dd/mm/yyyy" format?  Write a JavaScript program to find the area of a triangle where lengths of the three of its sides are 5, 6, 7  Write a JavaScript program to calculate multiplication and division of two numbers using functions(input from user).
  • 27. Assignments Assignment #1: Add field validations for HTML assignment #1 (Create an Employee Information Page) The following fields should be mandatory, appropriate error message should display if the field is left blank or entered with invalid data. • Name field : Accept only alphabets and Max 20 characters. • DOB (DD/MM/YYYY) • What do you do Section • Team Members text area • Mailing Address • Permanent Address • Email ID field Submit button : On clicking the ‘Submit’ button • Display message: “Thank you. Your details are submitted successfully”, if valid data is entered in all the fields • Display field level error message for each field, if invalid data is entered or filed is left blank. Clear button: On clicking the ‘Clear’ button • Entered data should be cleared for all the fields.
  • 28. Assignment #2: Add field validations for HTML assignment #2 (Create a webpage as below with your information) The following fields should be mandatory, appropriate error message should display if the field is left blank or entered with invalid data. • Name: Accept only alphabets and Max 40 characters. • Email: Accept alphabet, special characters & numbers, characters should present before and after @ symbol, end with .com/.org/.in • Gender ( radio button) • County( Drop down list) • Get back to me via: Email , Phone, Personally ( Check boxes) • Comments: Text area of a fixed size. Submit button : On clicking the ‘Submit’ button • Display message: “Thank you. Your details are submitted successfully”, if valid data is entered in all the fields • Display field level error message for each field, if invalid data is entered or filed is left blank.