SlideShare una empresa de Scribd logo
1 de 18
Descargar para leer sin conexión
JavaScript


      Summer Internship – 2012
(Indian Institute of Technology Bombay)



                                       Rajavel D
                              (Clicker Software)
JavaScript
   JavaScript is a scripting language

   Lightweight programming language

   Embedded directly into HTML pages

   JavaScript is an interpreted language (means
    that scripts execute without preliminary
    compilation)


      IITB                               - JSP
What can a JavaScript do?
   JavaScript gives HTML designers a
    programming tool
   JavaScript can put dynamic text into an HTML
    page
   JavaScript can react to events
   JavaScript can read and write HTML elements
   JavaScript can be used to validate data
   JavaScript can be used to create cookies

      IITB                                     - JSP
Sample JavaScript
<html>
<body>
<p id="demo"></p>
<script type="text/javascript">
<!--
document.getElementById("demo").innerHTML=Date();
//-->
</script>
</body>
</html>

        IITB                                        - JSP
JavaScript in <head>
<html> <head>
<script type="text/javascript">
function displayDate()
{   document.getElementById("demo").innerHTML=Date();     }
</script>
</head>
<body> <p id="demo"></p>
<button type="button" onclick="displayDate()">Display
Date</button>
</body> </html>

      IITB                                              - JSP
Using an External JavaScript
<head>
<script type="text/javascript" src="xxx.js"></script>
</head>
JavaScript Statements
   The semicolon is optional
   Using semicolons makes it possible to write multiple statements
    on one line.
   Each statement is executed by the browser in the sequence
    they are written



      IITB                                                - JSP
JavaScript Comments
   Single line comments start with //.
   Multi line comments start with /* and end with */.


JavaScript Popup Boxes
   alert("I am an alert box!");
   var r=confirm("Press a button");
     r = true | false
   var name=prompt("Please enter your name","");



      IITB                                           - JSP
JavaScript Events
   onLoad and onUnload
   onFocus, onBlur and onChange
   OnSubmit
   onMouseOver, onmousedown, onmouseout
   Onerror
   Onkeydown, onkeyup
   onselect


      IITB                            - JSP
Required Fields Validation
function validateForm()
{
var x=document.getElementById("txt").value
if (x==null || x=="")
    {
    alert("First name must be filled out");
    return false;
    }
}


         IITB                                 - JSP
E-mail Validation
function validateForm()
{
var x=document.forms["myForm"]["email"].value
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
    {
    alert("Not a valid e-mail address");
    return false;
    }
}        IITB                                          - JSP
JavaScript Advanced
Timing
setTimeout("MsgAfter3sec()",3000);
clearTimeout();
Object
<script type="text/javascript">
personObj={firstname:"John",lastname:"Doe",age:50,eyecolor:"blu
e"}
document.write(personObj.firstname + " is " + personObj.age + "
years old.");
</script>

      IITB                                               - JSP
JavaScript Cookies

   A cookie is a variable that is stored on the
    visitor's computer


   With JavaScript, you can both create and
    retrieve cookie values.




      IITB                                     - JSP
Document Object
   document.anchors/forms/images.length
   document.anchors[0].innerHTML
   document.title, document.URL
   document.getElementById("myHeader").innerHTML
   document.open("text/html","replace");doc.write(“<html>...</html>”);
   document.getElementsByTagName("input");
   document.getElementById("frm1").reset();
Event Object
   onmousedown="whichButton(event)", //event.button==2 --> right
   onkeyup="whichButton(event)"//event.keyCode --> ascii

       IITB                                                   - JSP
2D Animation
JavaScript library -> jsDraw2D.js (Free Source)
           http://code.google.com/
Create jsGraphics object :
  var gr = new jsGraphics(document.getElementById("div_id"))


Create jsColor object
  var col = new jsColor("red");


Create jsPen object
  var pen = new jsPen(col,1);

      IITB                                                 - JSP
2D Animation
Draw a Line between 2 points
  var pt1 = new jsPoint(20,30);
  var pt2 = new jsPoint(120,230);
  gr.drawLine(pen,pt1,pt2);


Draw filled circle with pt1 as center point and radius 30.
  gr.fillCircle(col,pt1,30);


You can also code with inline object instantiation like below
  gr.drawLine(pen,new jsPoint(40,10),new jsPoint(70,150));

      IITB                                                      - JSP
Draw Two Circle
<script type="text/javascript">
var graph = new jsGraphics(document.getElementById("container"));
var color1 = new jsColor("RED");
var color2 = new jsColor("#ADADAD");
var point1 = new jsPoint(50,50);
var point2 = new jsPoint(-40,50);
graph.fillCircle(color1,point1,40);
graph.fillCircle(color2,point2,30);
</script>



      IITB                                                  - JSP
Animation
var p = -3
function moveCircle(){
if(p<=150){ p = p+1;}
    else{ clearTimeout(t); }
    var graph = new jsGraphics(document.getElementById("container"));
             :
    var point1 = new jsPoint(50,50); var point2 = new jsPoint(p,50);
    graph.fillCircle(color1,point1,40); graph.fillCircle(color2,point2,30);
    t=setTimeout("timedCount()",50);
}

       IITB                                                        - JSP
References

www.w3schools.com/js/


http://jsdraw2d.jsfiction.com/


http://www.schillmania.com/content/projects/javascript-animation-1/


   http://berniesumption.com/software/animator/



      IITB                                                    - JSP

Más contenido relacionado

La actualidad más candente

JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 

La actualidad más candente (20)

Angular JS2 Training Session #1
Angular JS2 Training Session #1Angular JS2 Training Session #1
Angular JS2 Training Session #1
 
Java script tutorial
Java script tutorialJava script tutorial
Java script tutorial
 
KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 4/7KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 4/7
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2
 
Web 6 | JavaScript DOM
Web 6 | JavaScript DOMWeb 6 | JavaScript DOM
Web 6 | JavaScript DOM
 
JavaScript
JavaScriptJavaScript
JavaScript
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulation
 
Java script
Java scriptJava script
Java script
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery Basics
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
 
1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentals
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
 
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
 
22 j query1
22 j query122 j query1
22 j query1
 
Java script
Java scriptJava script
Java script
 
Lecture 5: Client Side Programming 1
Lecture 5: Client Side Programming 1Lecture 5: Client Side Programming 1
Lecture 5: Client Side Programming 1
 
Lecture 6: Client Side Programming 2
Lecture 6: Client Side Programming 2Lecture 6: Client Side Programming 2
Lecture 6: Client Side Programming 2
 
Web 5 | JavaScript Events
Web 5 | JavaScript EventsWeb 5 | JavaScript Events
Web 5 | JavaScript Events
 
jQuery - Chapter 5 - Ajax
jQuery - Chapter 5 -  AjaxjQuery - Chapter 5 -  Ajax
jQuery - Chapter 5 - Ajax
 
Java Script
Java ScriptJava Script
Java Script
 

Similar a Javascript

Similar a Javascript (20)

Java script
Java scriptJava script
Java script
 
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
 
Introduction of javascript
Introduction of javascriptIntroduction of javascript
Introduction of javascript
 
Wt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technologyWt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technology
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Implementation of GUI Framework part3
Implementation of GUI Framework part3Implementation of GUI Framework part3
Implementation of GUI Framework part3
 
e-suap - client technologies- english version
e-suap - client technologies- english versione-suap - client technologies- english version
e-suap - client technologies- english version
 
13-IntroJavascript.pptx
13-IntroJavascript.pptx13-IntroJavascript.pptx
13-IntroJavascript.pptx
 
13-IntroJavascript.pptx
13-IntroJavascript.pptx13-IntroJavascript.pptx
13-IntroJavascript.pptx
 
13-IntroJavascript.pptx
13-IntroJavascript.pptx13-IntroJavascript.pptx
13-IntroJavascript.pptx
 
Advance java
Advance javaAdvance java
Advance java
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fallHtml5 For Jjugccc2009fall
Html5 For Jjugccc2009fall
 
ASP.Net, move data to and from a SQL Server Database
ASP.Net, move data to and from a SQL Server DatabaseASP.Net, move data to and from a SQL Server Database
ASP.Net, move data to and from a SQL Server Database
 
Java script
Java scriptJava script
Java script
 
前端概述
前端概述前端概述
前端概述
 
Javascript - Beyond-jQuery
Javascript - Beyond-jQueryJavascript - Beyond-jQuery
Javascript - Beyond-jQuery
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Webdesing lab part-b__java_script_
Webdesing lab part-b__java_script_Webdesing lab part-b__java_script_
Webdesing lab part-b__java_script_
 

Último

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Último (20)

How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 

Javascript

  • 1. JavaScript Summer Internship – 2012 (Indian Institute of Technology Bombay) Rajavel D (Clicker Software)
  • 2. JavaScript  JavaScript is a scripting language  Lightweight programming language  Embedded directly into HTML pages  JavaScript is an interpreted language (means that scripts execute without preliminary compilation) IITB - JSP
  • 3. What can a JavaScript do?  JavaScript gives HTML designers a programming tool  JavaScript can put dynamic text into an HTML page  JavaScript can react to events  JavaScript can read and write HTML elements  JavaScript can be used to validate data  JavaScript can be used to create cookies IITB - JSP
  • 4. Sample JavaScript <html> <body> <p id="demo"></p> <script type="text/javascript"> <!-- document.getElementById("demo").innerHTML=Date(); //--> </script> </body> </html> IITB - JSP
  • 5. JavaScript in <head> <html> <head> <script type="text/javascript"> function displayDate() { document.getElementById("demo").innerHTML=Date(); } </script> </head> <body> <p id="demo"></p> <button type="button" onclick="displayDate()">Display Date</button> </body> </html> IITB - JSP
  • 6. Using an External JavaScript <head> <script type="text/javascript" src="xxx.js"></script> </head> JavaScript Statements  The semicolon is optional  Using semicolons makes it possible to write multiple statements on one line.  Each statement is executed by the browser in the sequence they are written IITB - JSP
  • 7. JavaScript Comments  Single line comments start with //.  Multi line comments start with /* and end with */. JavaScript Popup Boxes  alert("I am an alert box!");  var r=confirm("Press a button"); r = true | false  var name=prompt("Please enter your name",""); IITB - JSP
  • 8. JavaScript Events  onLoad and onUnload  onFocus, onBlur and onChange  OnSubmit  onMouseOver, onmousedown, onmouseout  Onerror  Onkeydown, onkeyup  onselect IITB - JSP
  • 9. Required Fields Validation function validateForm() { var x=document.getElementById("txt").value if (x==null || x=="") { alert("First name must be filled out"); return false; } } IITB - JSP
  • 10. E-mail Validation function validateForm() { var x=document.forms["myForm"]["email"].value var atpos=x.indexOf("@"); var dotpos=x.lastIndexOf("."); if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) { alert("Not a valid e-mail address"); return false; } } IITB - JSP
  • 12. JavaScript Cookies  A cookie is a variable that is stored on the visitor's computer  With JavaScript, you can both create and retrieve cookie values. IITB - JSP
  • 13. Document Object  document.anchors/forms/images.length  document.anchors[0].innerHTML  document.title, document.URL  document.getElementById("myHeader").innerHTML  document.open("text/html","replace");doc.write(“<html>...</html>”);  document.getElementsByTagName("input");  document.getElementById("frm1").reset(); Event Object  onmousedown="whichButton(event)", //event.button==2 --> right  onkeyup="whichButton(event)"//event.keyCode --> ascii IITB - JSP
  • 14. 2D Animation JavaScript library -> jsDraw2D.js (Free Source) http://code.google.com/ Create jsGraphics object : var gr = new jsGraphics(document.getElementById("div_id")) Create jsColor object var col = new jsColor("red"); Create jsPen object var pen = new jsPen(col,1); IITB - JSP
  • 15. 2D Animation Draw a Line between 2 points var pt1 = new jsPoint(20,30); var pt2 = new jsPoint(120,230); gr.drawLine(pen,pt1,pt2); Draw filled circle with pt1 as center point and radius 30. gr.fillCircle(col,pt1,30); You can also code with inline object instantiation like below gr.drawLine(pen,new jsPoint(40,10),new jsPoint(70,150)); IITB - JSP
  • 16. Draw Two Circle <script type="text/javascript"> var graph = new jsGraphics(document.getElementById("container")); var color1 = new jsColor("RED"); var color2 = new jsColor("#ADADAD"); var point1 = new jsPoint(50,50); var point2 = new jsPoint(-40,50); graph.fillCircle(color1,point1,40); graph.fillCircle(color2,point2,30); </script> IITB - JSP
  • 17. Animation var p = -3 function moveCircle(){ if(p<=150){ p = p+1;} else{ clearTimeout(t); } var graph = new jsGraphics(document.getElementById("container")); : var point1 = new jsPoint(50,50); var point2 = new jsPoint(p,50); graph.fillCircle(color1,point1,40); graph.fillCircle(color2,point2,30); t=setTimeout("timedCount()",50); } IITB - JSP