SlideShare a Scribd company logo
 
What is JavaScript JavaScript was designed to add interactivity to HTML pages  JavaScript is a scripting language (a scripting language is a lightweight programming language)  A JavaScript consists of lines of executable computer code  A JavaScript is usually embedded directly into HTML pages  JavaScript is an interpreted language (means that scripts execute without preliminary compilation)  Everyone can use JavaScript without purchasing a license
How javascript helps? Javascript gives designer a programming tool It can put dynamic text into HTML page Can respond to events – mouse over, click, page load etc Can read, write and manipulate HTML elements Can help validate use input Can detect version of browser
First Javascript <html> <body> <script type=&quot;text/javascript&quot;> document.write(&quot;Hello World!&quot;) </script> </body> </html>   Script Tag Indicates browser that it’s script that needs to be executed Type attributes indicates what type of script is this? This  is standard command to write stuff on webpage
Place for Javascript Java script can put either in ‘head’ section of html page or in ‘body’ section of html page. If put in body section – the script will be executed automatically when the page is loaded If it is put in head section – then script has to be called explicitly. By putting script in head you ensure that script is loaded first even before any part page uses it
Example <html> <head> <script type=text/javascript> </script> </head> <body> </body> </html> <html> <head> </head> <body> <script type=text/javascript> </script> </body> </html> Javascript in Head Javascript in body
Javascript in separate file Javascript can be present in separate file as well. You only need to refer it in your html. You would refer it in body if you want it to get executed on page load.  You would refer it in head if you want to execute it on an event. Files containing javascript has .js extention
Example <html> <head> <script src= myjscript.js > </script> </head> <body> </body> </html> <html> <head> </head> <body> <script  src=myjscript.js > </script> </body> </html> Javascript in Head Javascript in body
Javascript Quick Stuff Variable Need not put data type for variables. Variables are interpreted based on the values assigned. var  x = 10; var city = “Bangalore” Variables names are case sensitive
if(condition) { } if(condition) { } else { }
String Operations Var x = &quot;It is lot of pressure&quot; Var y = &quot;at Bredge&quot; Var z = x+y  => &quot;It is lot of pressure at Bredge&quot;
Loops For Loop: for(x=0; x <= 10; x++) { } While Loop: while(condition { } Do-while Loop: do { } while(condition) For-In for(variable in object) { }
For – In example <html> <body> <script type=&quot;text/javascript&quot;> var xvar mycars = new Array() mycars[0] = &quot;Saab&quot; mycars[1] = &quot;Volvo&quot; mycars[2] = &quot;BMW &quot; for (x in mycars) { document.write(mycars[x] + &quot;<br />&quot;) } </script> </body> </html>
Javascript popup boxes With javascript we can create popup boxes Three types of popup boxes Alert Box  Confirm Box Prompt Box
Example -AlertBox <html> <head> <script type=&quot;text/javascript&quot;> function disp_alert() { alert(&quot;I am an alert box!!&quot;) } </script> </head> <body> <input type=&quot;button&quot; onclick=&quot;disp_alert()&quot; value=&quot;Display alert box&quot; /> </body> </html>
Example Confirm Box <html> <head> <script type=&quot;text/javascript&quot;> function disp_confirm() { var r=confirm(&quot;Press a button&quot;) if (r==true) { document.write(&quot;You pressed OK!&quot;) } else { document.write(&quot;You pressed Cancel!&quot;) } } </script> </head> <body> <input type=&quot;button&quot; onclick=&quot;disp_confirm()&quot; value=&quot;Display a confirm box&quot; /> </body> </html>
Prompt Box <html> <head> <script type=&quot;text/javascript&quot;> function disp_prompt()   {   var name=prompt(&quot;Please enter your name&quot;,&quot;Harry Potter&quot;)   if (name!=null && name!=&quot;&quot;) { document.write(&quot;Hello &quot; + name + &quot;! How are you today?&quot;) }   } </script> </head> <body> <input type=&quot;button&quot; onclick=&quot;disp_prompt()&quot; value=&quot;Display a prompt box&quot; /> </body> </html>
Functions in JavaScript Functions are written in head section Functions do not have return type However function can return values Functions can take of arguments function  functionname ( var1,var2,...,varX ) { some code }   Functions are called upon document events such as onclick, mouseover and so on.
Function Example <html> <head> <script type=&quot;text/javascript&quot;> function product(a,b) { return a*b } </script> </head> <body> <script type=&quot;text/javascript&quot;> document.write(product(4,3)) </script> </body> </html>
Javascript events Every element of web page such as <body>,<table>,<form>,<input> and so on have events associated with them. When these events occur, a javascript piece of code or javascript function can be invoked Some of the important events are Mouse click  Webpage loading or image loading Mouse over Submitting a page
 
Example - Events <html> <head> <script type=text/javascript> function f1(msg) { alert(msg); } </script> </head> <body> <b>This example also shows bit layouting. You lay out components using table with border=0</b> <table> <tr> <td>Name</td> <td><input type='text' value=&quot;click me&quot; onclick=&quot;f1('you clicked on Name')&quot;></input></td> </tr> <tr> <td>Age</td> <td><input type=text value=&quot;double click here&quot; ondblclick=&quot;f1('you double clicked on Age')&quot;> </input></td> </tr> <tr> <td>Salary</td> <td><input type=text  value=&quot;type somethig here&quot; onchange=&quot;f1('you typed some data in Salary')&quot;> </input></td> </tr> </table> </body> </html>
onerror event Onerror event is fired when there is a script error Since script are not compiled, it will difficult catch typo and other mistakes.  Handling onerror will help identify the error. However this event is fired when the erroneous script is executed To handle this error we need provide a function which handles it. Onerror event provides three information – error message, url of the page where error is caused, line number where error is present. The handling function should take three parameters
Onerror Example <html> <head> <script type=&quot;text/javascript&quot;> onerror=handleErr var txt=&quot;&quot; function handleErr(msg,url,l) { txt=&quot;There was an error on this page.\n\n&quot; txt+=&quot;Error: &quot; + msg + &quot;\n&quot; txt+=&quot;URL: &quot; + url + &quot;\n&quot; txt+=&quot;Line: &quot; + l + &quot;\n\n&quot; txt+=&quot;Click OK to continue.\n\n&quot; alert(txt) return true } function message() { alert(&quot;Welcome guest!&quot;) } </script> </head> <body> <input type=&quot;button&quot; value=&quot;View message&quot; onclick=&quot;message()&quot; /> </body> </html>
Accessing Elements of Page Most often javascript need to access your elemets to validate information to Modify an attribute of an element to Dynamically put the values to add additional elements Element could be any html element such as <body>, <table>,<input>, <form> etc.
Accessing Elements of Page All the elements in a html document are stores like tree with <html></html> being root node Every element can be uniquely identified by giving unit id <intpu type=text id=  &quot; nameField &quot;  > All the attribute values can obtained using document object  var ele =   document.getElementById( &quot; nameField &quot; ) Attribute values of element can be accessed using ‘element’ variable ele.value()
Accessing Elements - Example <html> <head> <script type=text/javascript> function infoRead() {   ele1 = document.getElementById(&quot;name&quot;);   ele2 = document.getElementById(&quot;Age&quot;);   ele3 = document.getElementById(&quot;Salary&quot;);   alert(&quot;You have entered\n&quot;+   &quot;Name - &quot;+ele1.value +   &quot;\nAge - &quot; + ele2.value +   &quot;\nSalary - &quot;+ele3.value   ) } </script> </head> <body> <b>This example also shows bit layouting. You lay out components using table with border=0</b> <table>   <tr>   <td>Name</td> <td><input type='text' id=&quot;name&quot;></input></td>   </tr>   <tr>   <td>Age</td> <td><input type=text id=&quot;Age&quot;> </input></td>   </tr>   <tr>   <td>Salary</td> <td><input type=text  id=&quot;Salary&quot;> </input></td>   </tr> </table> <input type=submit onclick=&quot;infoRead()&quot; value=&quot;Sumit&quot;/> </body> </html>
Javascript Objects javascript is a object oriented language You can create your own objects Every object has property and methods javascript also provide predefined objects String object Date Object Array Object Math Object
Javascript DOM Objects HTML DOM – HTML  D ocument  O bject  M odel It defines standard set of objects for HTML and standard way to access them All HTML elements, their attributes and containing test can be manipulated using DOM
DOM object list
 
 
 
 
 
 
 
 
 
 
 
 

More Related Content

PPTX
Java Script
PPT
Java script
PPT
Java script
PPT
Java script
PPTX
Introduction to Java Script
PPT
JavaScript Missing Manual, Ch. 1
PPT
JAVA SCRIPT
PPTX
Java Script An Introduction By HWA
Java Script
Java script
Java script
Java script
Introduction to Java Script
JavaScript Missing Manual, Ch. 1
JAVA SCRIPT
Java Script An Introduction By HWA

What's hot (20)

PPTX
1. java script language fundamentals
PPTX
Java Script
PPT
Session vii(java scriptbasics)
PDF
Introduction to Javascript programming
PPTX
Introduction to java_script
DOC
Java script by Act Academy
DOC
Basics java scripts
PPTX
Java script
PPTX
Java script writing javascript
PPT
Java script
PPTX
Web designing unit 4
PPTX
Javascripts. pptt
PDF
JavaScript Jump Start 20220214
PPT
Java script programs
PDF
JavaScript guide 2020 Learn JavaScript
PPTX
Introduction To JavaScript
DOCX
Introduction of javascript
PPT
JavaScript - Part-1
1. java script language fundamentals
Java Script
Session vii(java scriptbasics)
Introduction to Javascript programming
Introduction to java_script
Java script by Act Academy
Basics java scripts
Java script
Java script writing javascript
Java script
Web designing unit 4
Javascripts. pptt
JavaScript Jump Start 20220214
Java script programs
JavaScript guide 2020 Learn JavaScript
Introduction To JavaScript
Introduction of javascript
JavaScript - Part-1
Ad

Viewers also liked (20)

PDF
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
PPTX
The big bang theory - UNIT 2
PDF
Introduction to JavaScript: Week Two
PDF
An Introduction to JavaScript: Week 5
PDF
Unchallengeable miracle of Holy Quran
PPTX
8. java script
PPTX
The big bang theory of social recruiting
PDF
An Introduction to JavaScript: Week 4
PDF
An Introduction to JavaScript: Week 3
PDF
An Introduction to JavaScript: Week One
PPTX
Big Bang Theory
PPT
Java script -23jan2015
PPT
Chapter 1 - How the world begin
PPTX
Big Bang Theorychandler
PPTX
Qur’an and its sciences
PDF
Large-Scale JavaScript Development
PPT
Java script Learn Easy
PPT
The Quran and Computational Linguistics
PPTX
Evolution of universe
PDF
Quranic concept of human life cycle urdu
The Big Bang Theory: Nine Steps To Building Your Meetup Empire
The big bang theory - UNIT 2
Introduction to JavaScript: Week Two
An Introduction to JavaScript: Week 5
Unchallengeable miracle of Holy Quran
8. java script
The big bang theory of social recruiting
An Introduction to JavaScript: Week 4
An Introduction to JavaScript: Week 3
An Introduction to JavaScript: Week One
Big Bang Theory
Java script -23jan2015
Chapter 1 - How the world begin
Big Bang Theorychandler
Qur’an and its sciences
Large-Scale JavaScript Development
Java script Learn Easy
The Quran and Computational Linguistics
Evolution of universe
Quranic concept of human life cycle urdu
Ad

Similar to Java Script (20)

PPT
KMUTNB - Internet Programming 3/7
PPT
JWU Guest Talk: JavaScript and AJAX
PPT
Javascript: Ajax & DOM Manipulation v1.2
ODP
Developing and testing ajax components
PPT
Developing Gadgets
PPT
JavaScript
PPT
Vb.Net Web Forms
PDF
Javascript Basic
PPT
JSP Custom Tags
PPT
Lecture 5 - Comm Lab: Web @ ITP
PPT
Week7
 
PPT
HTML Fundamentals
PPT
YL Intro html
PPT
Everything You Always Wanted To Know About XML But Were Afraid To Ask
ODP
JavaScript and jQuery Fundamentals
PPT
Migration testing framework
PPT
Ajax ons2
PPT
Introduction To Lamp
PPT
Introduction to html
PPT
Introduction to html
KMUTNB - Internet Programming 3/7
JWU Guest Talk: JavaScript and AJAX
Javascript: Ajax & DOM Manipulation v1.2
Developing and testing ajax components
Developing Gadgets
JavaScript
Vb.Net Web Forms
Javascript Basic
JSP Custom Tags
Lecture 5 - Comm Lab: Web @ ITP
Week7
 
HTML Fundamentals
YL Intro html
Everything You Always Wanted To Know About XML But Were Afraid To Ask
JavaScript and jQuery Fundamentals
Migration testing framework
Ajax ons2
Introduction To Lamp
Introduction to html
Introduction to html

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
cuic standard and advanced reporting.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Cloud computing and distributed systems.
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
KodekX | Application Modernization Development
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Network Security Unit 5.pdf for BCA BBA.
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Spectroscopy.pptx food analysis technology
cuic standard and advanced reporting.pdf
sap open course for s4hana steps from ECC to s4
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Empathic Computing: Creating Shared Understanding
Advanced methodologies resolving dimensionality complications for autism neur...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Cloud computing and distributed systems.
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Digital-Transformation-Roadmap-for-Companies.pptx
KodekX | Application Modernization Development
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation_ Review paper, used for researhc scholars
NewMind AI Weekly Chronicles - August'25 Week I
Agricultural_Statistics_at_a_Glance_2022_0.pdf

Java Script

  • 1.  
  • 2. What is JavaScript JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language (a scripting language is a lightweight programming language) A JavaScript consists of lines of executable computer code A JavaScript is usually embedded directly into HTML pages JavaScript is an interpreted language (means that scripts execute without preliminary compilation) Everyone can use JavaScript without purchasing a license
  • 3. How javascript helps? Javascript gives designer a programming tool It can put dynamic text into HTML page Can respond to events – mouse over, click, page load etc Can read, write and manipulate HTML elements Can help validate use input Can detect version of browser
  • 4. First Javascript <html> <body> <script type=&quot;text/javascript&quot;> document.write(&quot;Hello World!&quot;) </script> </body> </html> Script Tag Indicates browser that it’s script that needs to be executed Type attributes indicates what type of script is this? This is standard command to write stuff on webpage
  • 5. Place for Javascript Java script can put either in ‘head’ section of html page or in ‘body’ section of html page. If put in body section – the script will be executed automatically when the page is loaded If it is put in head section – then script has to be called explicitly. By putting script in head you ensure that script is loaded first even before any part page uses it
  • 6. Example <html> <head> <script type=text/javascript> </script> </head> <body> </body> </html> <html> <head> </head> <body> <script type=text/javascript> </script> </body> </html> Javascript in Head Javascript in body
  • 7. Javascript in separate file Javascript can be present in separate file as well. You only need to refer it in your html. You would refer it in body if you want it to get executed on page load. You would refer it in head if you want to execute it on an event. Files containing javascript has .js extention
  • 8. Example <html> <head> <script src= myjscript.js > </script> </head> <body> </body> </html> <html> <head> </head> <body> <script src=myjscript.js > </script> </body> </html> Javascript in Head Javascript in body
  • 9. Javascript Quick Stuff Variable Need not put data type for variables. Variables are interpreted based on the values assigned. var x = 10; var city = “Bangalore” Variables names are case sensitive
  • 10. if(condition) { } if(condition) { } else { }
  • 11. String Operations Var x = &quot;It is lot of pressure&quot; Var y = &quot;at Bredge&quot; Var z = x+y => &quot;It is lot of pressure at Bredge&quot;
  • 12. Loops For Loop: for(x=0; x <= 10; x++) { } While Loop: while(condition { } Do-while Loop: do { } while(condition) For-In for(variable in object) { }
  • 13. For – In example <html> <body> <script type=&quot;text/javascript&quot;> var xvar mycars = new Array() mycars[0] = &quot;Saab&quot; mycars[1] = &quot;Volvo&quot; mycars[2] = &quot;BMW &quot; for (x in mycars) { document.write(mycars[x] + &quot;<br />&quot;) } </script> </body> </html>
  • 14. Javascript popup boxes With javascript we can create popup boxes Three types of popup boxes Alert Box Confirm Box Prompt Box
  • 15. Example -AlertBox <html> <head> <script type=&quot;text/javascript&quot;> function disp_alert() { alert(&quot;I am an alert box!!&quot;) } </script> </head> <body> <input type=&quot;button&quot; onclick=&quot;disp_alert()&quot; value=&quot;Display alert box&quot; /> </body> </html>
  • 16. Example Confirm Box <html> <head> <script type=&quot;text/javascript&quot;> function disp_confirm() { var r=confirm(&quot;Press a button&quot;) if (r==true) { document.write(&quot;You pressed OK!&quot;) } else { document.write(&quot;You pressed Cancel!&quot;) } } </script> </head> <body> <input type=&quot;button&quot; onclick=&quot;disp_confirm()&quot; value=&quot;Display a confirm box&quot; /> </body> </html>
  • 17. Prompt Box <html> <head> <script type=&quot;text/javascript&quot;> function disp_prompt() { var name=prompt(&quot;Please enter your name&quot;,&quot;Harry Potter&quot;) if (name!=null && name!=&quot;&quot;) { document.write(&quot;Hello &quot; + name + &quot;! How are you today?&quot;) } } </script> </head> <body> <input type=&quot;button&quot; onclick=&quot;disp_prompt()&quot; value=&quot;Display a prompt box&quot; /> </body> </html>
  • 18. Functions in JavaScript Functions are written in head section Functions do not have return type However function can return values Functions can take of arguments function functionname ( var1,var2,...,varX ) { some code } Functions are called upon document events such as onclick, mouseover and so on.
  • 19. Function Example <html> <head> <script type=&quot;text/javascript&quot;> function product(a,b) { return a*b } </script> </head> <body> <script type=&quot;text/javascript&quot;> document.write(product(4,3)) </script> </body> </html>
  • 20. Javascript events Every element of web page such as <body>,<table>,<form>,<input> and so on have events associated with them. When these events occur, a javascript piece of code or javascript function can be invoked Some of the important events are Mouse click Webpage loading or image loading Mouse over Submitting a page
  • 21.  
  • 22. Example - Events <html> <head> <script type=text/javascript> function f1(msg) { alert(msg); } </script> </head> <body> <b>This example also shows bit layouting. You lay out components using table with border=0</b> <table> <tr> <td>Name</td> <td><input type='text' value=&quot;click me&quot; onclick=&quot;f1('you clicked on Name')&quot;></input></td> </tr> <tr> <td>Age</td> <td><input type=text value=&quot;double click here&quot; ondblclick=&quot;f1('you double clicked on Age')&quot;> </input></td> </tr> <tr> <td>Salary</td> <td><input type=text value=&quot;type somethig here&quot; onchange=&quot;f1('you typed some data in Salary')&quot;> </input></td> </tr> </table> </body> </html>
  • 23. onerror event Onerror event is fired when there is a script error Since script are not compiled, it will difficult catch typo and other mistakes. Handling onerror will help identify the error. However this event is fired when the erroneous script is executed To handle this error we need provide a function which handles it. Onerror event provides three information – error message, url of the page where error is caused, line number where error is present. The handling function should take three parameters
  • 24. Onerror Example <html> <head> <script type=&quot;text/javascript&quot;> onerror=handleErr var txt=&quot;&quot; function handleErr(msg,url,l) { txt=&quot;There was an error on this page.\n\n&quot; txt+=&quot;Error: &quot; + msg + &quot;\n&quot; txt+=&quot;URL: &quot; + url + &quot;\n&quot; txt+=&quot;Line: &quot; + l + &quot;\n\n&quot; txt+=&quot;Click OK to continue.\n\n&quot; alert(txt) return true } function message() { alert(&quot;Welcome guest!&quot;) } </script> </head> <body> <input type=&quot;button&quot; value=&quot;View message&quot; onclick=&quot;message()&quot; /> </body> </html>
  • 25. Accessing Elements of Page Most often javascript need to access your elemets to validate information to Modify an attribute of an element to Dynamically put the values to add additional elements Element could be any html element such as <body>, <table>,<input>, <form> etc.
  • 26. Accessing Elements of Page All the elements in a html document are stores like tree with <html></html> being root node Every element can be uniquely identified by giving unit id <intpu type=text id= &quot; nameField &quot; > All the attribute values can obtained using document object var ele = document.getElementById( &quot; nameField &quot; ) Attribute values of element can be accessed using ‘element’ variable ele.value()
  • 27. Accessing Elements - Example <html> <head> <script type=text/javascript> function infoRead() { ele1 = document.getElementById(&quot;name&quot;); ele2 = document.getElementById(&quot;Age&quot;); ele3 = document.getElementById(&quot;Salary&quot;); alert(&quot;You have entered\n&quot;+ &quot;Name - &quot;+ele1.value + &quot;\nAge - &quot; + ele2.value + &quot;\nSalary - &quot;+ele3.value ) } </script> </head> <body> <b>This example also shows bit layouting. You lay out components using table with border=0</b> <table> <tr> <td>Name</td> <td><input type='text' id=&quot;name&quot;></input></td> </tr> <tr> <td>Age</td> <td><input type=text id=&quot;Age&quot;> </input></td> </tr> <tr> <td>Salary</td> <td><input type=text id=&quot;Salary&quot;> </input></td> </tr> </table> <input type=submit onclick=&quot;infoRead()&quot; value=&quot;Sumit&quot;/> </body> </html>
  • 28. Javascript Objects javascript is a object oriented language You can create your own objects Every object has property and methods javascript also provide predefined objects String object Date Object Array Object Math Object
  • 29. Javascript DOM Objects HTML DOM – HTML D ocument O bject M odel It defines standard set of objects for HTML and standard way to access them All HTML elements, their attributes and containing test can be manipulated using DOM
  • 31.  
  • 32.  
  • 33.  
  • 34.  
  • 35.  
  • 36.  
  • 37.  
  • 38.  
  • 39.  
  • 40.  
  • 41.  
  • 42.