SlideShare une entreprise Scribd logo
1  sur  18
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Angular JS2 Training Session #1
Angular JS2 Training Session #1Angular JS2 Training Session #1
Angular JS2 Training Session #1Paras Mendiratta
 
Java script tutorial
Java script tutorialJava script tutorial
Java script tutorialDoeun KOCH
 
KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 4/7KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 4/7phuphax
 
Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2Javascript: Ajax & DOM Manipulation v1.2
Javascript: Ajax & DOM Manipulation v1.2borkweb
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulationborkweb
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery BasicsKaloyan Kosev
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJamshid Hashimi
 
1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentalsRajiv Gupta
 
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 Ayes Chinmay
 
jQuery - Chapter 5 - Ajax
jQuery - Chapter 5 -  AjaxjQuery - Chapter 5 -  Ajax
jQuery - Chapter 5 - AjaxWebStackAcademy
 

Tendances (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
 

Similaire à Javascript

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...Ayes Chinmay
 
Introduction of javascript
Introduction of javascriptIntroduction of javascript
Introduction of javascriptsyeda zoya mehdi
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
Implementation of GUI Framework part3
Implementation of GUI Framework part3Implementation of GUI Framework part3
Implementation of GUI Framework part3masahiroookubo
 
e-suap - client technologies- english version
e-suap - client technologies- english versione-suap - client technologies- english version
e-suap - client technologies- english versionSabino Labarile
 
13-IntroJavascript.pptx
13-IntroJavascript.pptx13-IntroJavascript.pptx
13-IntroJavascript.pptxsuchita74
 
13-IntroJavascript.pptx
13-IntroJavascript.pptx13-IntroJavascript.pptx
13-IntroJavascript.pptxssuserd695d1
 
13-IntroJavascript.pptx
13-IntroJavascript.pptx13-IntroJavascript.pptx
13-IntroJavascript.pptxShilpaBhojne
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to JavascriptAnjan Banda
 
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 DatabaseChristopher Singleton
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingHoat Le
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 
Webdesing lab part-b__java_script_
Webdesing lab part-b__java_script_Webdesing lab part-b__java_script_
Webdesing lab part-b__java_script_Shivanand Algundi
 

Similaire à 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_
 

Dernier

Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
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...Poonam Aher Patil
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
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.pptxMaritesTamaniVerdade
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
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Ữ Â...Nguyen Thanh Tu Collection
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
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.pptxAreebaZafar22
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 

Dernier (20)

Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
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...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
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
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
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Ữ Â...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
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
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 

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