SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Sukrit Gupta
sukritgupta91@gmail.com
• Invented by Brendan Eich at Netscape, in1995.
• JavaScript is a programming language designed for Web pages.
• JAVASCRIPT is used to maintain BEHAVIOR of the document.
• JavaScript is used in millions of Web pages to improve the
  design, validate forms, detect browsers, create cookies, and
  much more.
• JavaScript is the most popular scripting language on the
  internet, and works in all major browsers, such as Internet
  Explorer, Mozilla, Firefox, Netscape, Opera.
• JavaScript is an interpreted language (means that scripts execute
  without preliminary compilation)
• Everyone can use JavaScript without purchasing a license
• Unlike HTML, JavaScript is case sensitive.
 Requires the JDK to create        Requires a text editor
  the applet
                                    Required a browser that can
 Requires a Java virtual            interpret JavaScript code
  machine to run the applet
                                    JavaScript can be placed
 Applet files are distinct from
  the HTML code                      within HTML and XHTML

 Source code is hidden from        Source code is made
  the user                           accessible to the user
 Programs must be saved as         Programs cannot write
  separate files and compiled        content to the hard disk
  before they can be run
                                    Programs run on the client
 Programs run on the server         side
  side
• JavaScript code is included within <script> tags:
   • <script type="text/javascript">
        document.write("<h1>Hello World!</h1>") ;
     </script>
• Notes:
    • The type attribute is to allow to use other scripting languages (but
       JavaScript is the default)
    • This simple code does the same thing as just putting <h1>Hello
       World!</h1> in the same place in the HTML document
    • The semicolon at the end of the JavaScript statement is optional.
    • We need semicolons if you put two or more statements on the
       same line.
• JavaScript can be put in the <head> or in the <body> of an HTML
  document
    • JavaScript functions should be defined in the <head>
        • This ensures that the function is loaded before it is needed
    • JavaScript in the <body> will be executed as the page loads
• JavaScript functions can be put in a separate .js file
   • <script src="myJavaScriptFile.js"></script>
    • Put this in the <head>
    • An external .js file lets us use the same JavaScript on multiple
       HTML pages
    • The external .js file cannot itself contain a <script> tag
• JavaScript can be put in an HTML form Object, such as a button
    • This JavaScript will be executed when the form object is used
• Some old browsers do not recognize script tags
   •   These browsers will ignore the script tags but will display the included
       JavaScript
   •   To get old browsers to ignore the whole thing, use:
          <script type="text/javascript">
          <!--
             document.write("Hello World!")
          //-->
          </script>
   •   The <!-- introduces an HTML comment
   •   To get JavaScript to ignore the HTML close comment, -->, the // starts
       a JavaScript comment, which extends to the end of the line
• Some users turn off JavaScript
   •   Use the <noscript>message</noscript> to display a message in place
       of whatever the JavaScript would put there
Manipulating HTML Elements       Writing to The Document Output
• <p id="demo">My First
                                   • <h1>My First Web Page</h1>
  Paragraph</p>
                                   <script>
  <script>                                   document.write("<p>My First
  document.getElementById("demo"             JavaScript</p>");
  ).innerHTML="My First            </script>
  JavaScript";
  </script>
• Variables are declared with a var statement:
   • var pi = 3.1416, x, y, name = "Dr. Dave" ;
   • Variables names must begin with a letter or underscore
   • Variable names are case-sensitive
   • Variables are untyped (they can hold values of any type)
   • The word var is optional
  Variables declared within a function are local to that function
   (accessible only within that function)
• Variables declared outside a function are global (accessible from
  anywhere on the page)
• Dynamic Typing - Variables can hold any valid type of value:
– Number … var myInt = 7;
– Boolean … var myBool = true;
– Function …var fname= function() { ……. };
– Object …... var person={firstname:"John", lastname:"Doe", id:5566};
– Array ……. var myArr = new Array();
– String …….var myString = ―abc‖;
– … and can hold values of different types at different times during
         execution.
Arithmetic Operators   Assignment Operators
Comparison Operators   Logical Operators
Alert Box                                  Confirm Box
                                       A confirm box is often used if we
 An alert box is often used if we      want the user to verify or accept
 want to make sure information          something.
 comes through to the user.
                                       When a confirm box pops up, the
 When an alert box pops up, the        user will have to click either "OK" or
 user will have to click "OK" to        "Cancel" to proceed.
 proceed.
<script>alert("Hello World!")</script>  If the user clicks "OK", the box
                                         returns true. If the user clicks
                                         "Cancel", the box returns false.
                                       • <script>confirm(―Sure??")</script>
•   Prompt Box
   • A prompt box is often used if we want the user to input a value .
   • When a prompt box pops up, the user will have to click either "OK"
       or "Cancel" to proceed after entering an input value.
   • If the user clicks "OK―, the box returns the input value. If the user
       clicks "Cancel―, the box returns null.
• <script> var name=prompt("Please enter your name","Harry");</script>
•       „if‟ statement
    •      if ( boolean statement ) {…}    else {…}
•       „switch‟ statement
    •      switch ( myVar ) {
    •                case 1:              // if myVar is equal to 1 this is executed
    •                break;
    •                case “two”:          // if myVar is equal to “two” this is executed
    •                break;
    •                case default:        // if none of the cases above are satisfied OR if no
    •                                     // „break‟ statement are used in the cases above,
    •                                     // this will be executed
    •               }
•       The For Loop
    •     SYNTAX:            for (start; condition; update) {JavaScript
          Commands}
    •     start is the starting value of the counter.
    •     condition is a Boolean expression that must be true for the loop to
          continue
    •     update specifies how the counter changes in value each time the
          command block is executed
    •     Example             for (var i=0; i<4; i++) { j++; }
•       The While Loop
    •     SYNTAX:          while (condition) { JavaScript Commands}
    •     condition is a Boolean expression that can be either true or false
    •     Example          while (var i<=10) { j++; i++;}
•       The Do While Loop
    •     SYNTAX:          do statement while (condition);
• Functions should be defined in the <head> of an HTML page, to ensure
   that they are loaded first
 • The syntax for defining a function is:
                function fname(arg1, …, argN) { statements }
 • The function may return value.
 • Any variables declared within the function are local to it.
 • The syntax for calling a function is just
                name(arg1, …, argN)
 • Simple parameters are passed by value, objects are passed by
   reference
• Function names are case-sensitive.
• There is no limit to the number of function parameters that a function
  may contain.


   •
• An object is just a special kind of data, with properties and methods.
  • Almost everything in JavaScript is an Object: String, Number, Array,
    Function, image.... Ex document.bgcolor          document.write(‖Hello");
  •                                                   document is the object. is the object.
                                                                   document
  •                                                   bgcolor is the property. method.
                                                                   write is the
• We can also create our own objects:
      •   SYNTAX: { name1 : value1 , ... , nameN : valueN }
      •   EXAMPLE: car = {myCar: "Saturn", variant: "Mazda", special: Sales}
      •   Example use: document.write("I own a " + car.myCar);

      •   Using new:
          •   var course = new Object();     •   Using a constructor:
              course.number = "CIT597";
                                                 •   function Course(n, t) { // best placed in <head>
              course.teacher = "Dr. Dave";
                                                        this.number = n;     // keyword "this" is required,
                                                         this.teacher = t;       //not optional
                                                     }
                                                 •   var course = new Course("CIT597", "Dr. Dave");

      •
• Events are actions that occur usually as a result of something the user
  does. For example, clicking a button is an event, as is changing a text
  field or moving the mouse over a hyperlink.
• We write our scripts so they execute by reacting to events within a web
  browser.
• Since events are at the heart of JavaScript programming, we need a way
  to detect events. We do that by using built-in event handlers …
• Eg: Click, change, focus, load, mouseover, mouseout, reset, submit.
         <input type=―button‖ onClick=―javascript:doButton()‖>
    • //calls function when button is clicked.
           <body onLoad=―javascript:init()‖>
•    //calls   function when page is loaded.




     •
•
• DOM stands for Document Object
  Model.
• It is a platform and language-neutral
  interface that allows programs and
  scripts to dynamically access and
  update the content, structure, and style
  of a document.
• The HTML DOM defines a standard for
  accessing and manipulating HTML
  documents.
• DOM is a tree of Objects
• Contents can be modified or deleted
• New elements can be created and
  inserted into the DOM Tree
• The document object is the JavaScript interface to the DOM of any HTML
  page.
• Accessing elements:
        – By name
   •                    document.getElementsByTagName(‗td')[indexOfColumn];
   •           –By ID
   •                    document.getElementById('id');
   •           – Walk the DOM Tree
   •                    document.childNodes[0].childNodes[1].childNodes[4];


       •
• JavaScript provides some limited, persistent storage, called
  cookies:
   •– Data is stored in a text file on the client
   •– name=value
   •–Multiple values are delimited by a semicolon
• Use sparingly. There are limits (generally):
   •– Up to 300 cookies per browser, 20 cookies per web server, and 4 KB of data
   per cookie
• Don‘t depend on cookies—users can block or delete them.
• By default, cookies are destroyed when the browser window is
  closed, unless we explicitly set the expires attribute.
   • – To persist a cookie, set the expires attribute to a future date.
   • – To delete a cookie, set the expires attribute to a past date.
• By default, cookies can only be read by the web page that wrote
  them unless we specify one or more of these attributes:
   • – path – allows more than one page on the site to read a cookie.(default value:
     /)
   • – domain – allows multiple servers to read a cookie.
   • -name – An identifier by which we reference a particular cookie.
   • -value – The information we wish to save, in reference to a particular cookie.
   • -expires – A GMT-formatted date specifying the date (in milliseconds) when a
     cookie will expire.
  SYNTAX to create a cookie:
    •   document.cookie = "username=" + who + ";‖ + "expires=" + expDate.toGMTString();+
        ―path=/‖
• Difficult because the language is interpreted.
   • – No compiler errors/warnings.
   • – Browser will try to run the script, errors and all.
• Make each line as granular as possible (use variables).
• Use alerts to get values of variables and see which lines are not
  getting processed.
• When testing form validation, set the action attribute to a dummy
  HTML page—not the server-side form. If you get the page, the
  script works.
• Try add-on like Firebug to detect problem.
• JavaScript is not totally platform independent
   • – Expect different browsers to behave differently
   • – Check whether the browser supports the functionality or not.
Java Script basics and DOM

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Java script basics
Java script basicsJava script basics
Java script basics
 
Javascript
JavascriptJavascript
Javascript
 
Java script
Java scriptJava script
Java script
 
JavaScript Good Practices
JavaScript Good PracticesJavaScript Good Practices
JavaScript Good Practices
 
Javascript and Jquery Best practices
Javascript and Jquery Best practicesJavascript and Jquery Best practices
Javascript and Jquery Best practices
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
 
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSONAn introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
 
Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best Practices
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptJavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScript
 
Java script
Java scriptJava script
Java script
 
Java script
Java scriptJava script
Java script
 
Java scripts
Java scriptsJava scripts
Java scripts
 
Java script
Java scriptJava script
Java script
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
 
JS Event Loop
JS Event LoopJS Event Loop
JS Event Loop
 
1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentals
 
Java script tutorial
Java script tutorialJava script tutorial
Java script tutorial
 
Java script
Java scriptJava script
Java script
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
Angular JS2 Training Session #1
Angular JS2 Training Session #1Angular JS2 Training Session #1
Angular JS2 Training Session #1
 

Ähnlich wie Java Script basics and DOM

Ähnlich wie Java Script basics and DOM (20)

BITM3730Week6.pptx
BITM3730Week6.pptxBITM3730Week6.pptx
BITM3730Week6.pptx
 
Java script
Java scriptJava script
Java script
 
Javascript Basics by Bonny
Javascript Basics by BonnyJavascript Basics by Bonny
Javascript Basics by Bonny
 
JavaScript
JavaScriptJavaScript
JavaScript
 
JavaScript
JavaScriptJavaScript
JavaScript
 
BITM3730 10-4.pptx
BITM3730 10-4.pptxBITM3730 10-4.pptx
BITM3730 10-4.pptx
 
BITM3730 10-3.pptx
BITM3730 10-3.pptxBITM3730 10-3.pptx
BITM3730 10-3.pptx
 
UNIT 3.ppt
UNIT 3.pptUNIT 3.ppt
UNIT 3.ppt
 
Java script
Java scriptJava script
Java script
 
Hsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdfHsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdf
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
JavaScript_III.pptx
JavaScript_III.pptxJavaScript_III.pptx
JavaScript_III.pptx
 
JavaScript_introduction_upload.pdf
JavaScript_introduction_upload.pdfJavaScript_introduction_upload.pdf
JavaScript_introduction_upload.pdf
 
Unit 4(it workshop)
Unit 4(it workshop)Unit 4(it workshop)
Unit 4(it workshop)
 
BITM3730 10-17.pptx
BITM3730 10-17.pptxBITM3730 10-17.pptx
BITM3730 10-17.pptx
 
WT Unit-3 PPT.pptx
WT Unit-3 PPT.pptxWT Unit-3 PPT.pptx
WT Unit-3 PPT.pptx
 
Intro to javascript (6:27)
Intro to javascript (6:27)Intro to javascript (6:27)
Intro to javascript (6:27)
 
Intro to JavaScript - Thinkful LA, June 2017
Intro to JavaScript - Thinkful LA, June 2017Intro to JavaScript - Thinkful LA, June 2017
Intro to JavaScript - Thinkful LA, June 2017
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
 
Thinkful - Intro to JavaScript
Thinkful - Intro to JavaScriptThinkful - Intro to JavaScript
Thinkful - Intro to JavaScript
 

Mehr von Sukrit Gupta

C Language - Switch and For Loop
C Language - Switch and For LoopC Language - Switch and For Loop
C Language - Switch and For LoopSukrit Gupta
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen ProblemSukrit Gupta
 
Future Technologies - Integral Cord
Future Technologies - Integral CordFuture Technologies - Integral Cord
Future Technologies - Integral CordSukrit Gupta
 
Harmful Effect Of Computers On Environment - EWASTE
Harmful Effect Of Computers On Environment - EWASTE Harmful Effect Of Computers On Environment - EWASTE
Harmful Effect Of Computers On Environment - EWASTE Sukrit Gupta
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessionsSukrit Gupta
 

Mehr von Sukrit Gupta (8)

C Language - Switch and For Loop
C Language - Switch and For LoopC Language - Switch and For Loop
C Language - Switch and For Loop
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
 
Future Technologies - Integral Cord
Future Technologies - Integral CordFuture Technologies - Integral Cord
Future Technologies - Integral Cord
 
Harmful Effect Of Computers On Environment - EWASTE
Harmful Effect Of Computers On Environment - EWASTE Harmful Effect Of Computers On Environment - EWASTE
Harmful Effect Of Computers On Environment - EWASTE
 
MySql
MySqlMySql
MySql
 
Html n CSS
Html n CSSHtml n CSS
Html n CSS
 
Html and css
Html and cssHtml and css
Html and css
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 

Kürzlich hochgeladen

4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptxmary850239
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...DhatriParmar
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxDhatriParmar
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptxJonalynLegaspi2
 

Kürzlich hochgeladen (20)

4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptx
 

Java Script basics and DOM

  • 2. • Invented by Brendan Eich at Netscape, in1995. • JavaScript is a programming language designed for Web pages. • JAVASCRIPT is used to maintain BEHAVIOR of the document. • JavaScript is used in millions of Web pages to improve the design, validate forms, detect browsers, create cookies, and much more. • JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as Internet Explorer, Mozilla, Firefox, Netscape, Opera. • JavaScript is an interpreted language (means that scripts execute without preliminary compilation) • Everyone can use JavaScript without purchasing a license • Unlike HTML, JavaScript is case sensitive.
  • 3.  Requires the JDK to create  Requires a text editor the applet  Required a browser that can  Requires a Java virtual interpret JavaScript code machine to run the applet  JavaScript can be placed  Applet files are distinct from the HTML code within HTML and XHTML  Source code is hidden from  Source code is made the user accessible to the user  Programs must be saved as  Programs cannot write separate files and compiled content to the hard disk before they can be run  Programs run on the client  Programs run on the server side side
  • 4. • JavaScript code is included within <script> tags: • <script type="text/javascript"> document.write("<h1>Hello World!</h1>") ; </script> • Notes: • The type attribute is to allow to use other scripting languages (but JavaScript is the default) • This simple code does the same thing as just putting <h1>Hello World!</h1> in the same place in the HTML document • The semicolon at the end of the JavaScript statement is optional. • We need semicolons if you put two or more statements on the same line.
  • 5. • JavaScript can be put in the <head> or in the <body> of an HTML document • JavaScript functions should be defined in the <head> • This ensures that the function is loaded before it is needed • JavaScript in the <body> will be executed as the page loads • JavaScript functions can be put in a separate .js file • <script src="myJavaScriptFile.js"></script> • Put this in the <head> • An external .js file lets us use the same JavaScript on multiple HTML pages • The external .js file cannot itself contain a <script> tag • JavaScript can be put in an HTML form Object, such as a button • This JavaScript will be executed when the form object is used
  • 6. • Some old browsers do not recognize script tags • These browsers will ignore the script tags but will display the included JavaScript • To get old browsers to ignore the whole thing, use: <script type="text/javascript"> <!-- document.write("Hello World!") //--> </script> • The <!-- introduces an HTML comment • To get JavaScript to ignore the HTML close comment, -->, the // starts a JavaScript comment, which extends to the end of the line • Some users turn off JavaScript • Use the <noscript>message</noscript> to display a message in place of whatever the JavaScript would put there
  • 7. Manipulating HTML Elements Writing to The Document Output • <p id="demo">My First • <h1>My First Web Page</h1> Paragraph</p> <script> <script> document.write("<p>My First document.getElementById("demo" JavaScript</p>"); ).innerHTML="My First </script> JavaScript"; </script>
  • 8. • Variables are declared with a var statement: • var pi = 3.1416, x, y, name = "Dr. Dave" ; • Variables names must begin with a letter or underscore • Variable names are case-sensitive • Variables are untyped (they can hold values of any type) • The word var is optional  Variables declared within a function are local to that function (accessible only within that function) • Variables declared outside a function are global (accessible from anywhere on the page)
  • 9. • Dynamic Typing - Variables can hold any valid type of value: – Number … var myInt = 7; – Boolean … var myBool = true; – Function …var fname= function() { ……. }; – Object …... var person={firstname:"John", lastname:"Doe", id:5566}; – Array ……. var myArr = new Array(); – String …….var myString = ―abc‖; – … and can hold values of different types at different times during execution.
  • 10. Arithmetic Operators Assignment Operators
  • 11. Comparison Operators Logical Operators
  • 12. Alert Box Confirm Box  A confirm box is often used if we An alert box is often used if we want the user to verify or accept want to make sure information something. comes through to the user.  When a confirm box pops up, the When an alert box pops up, the user will have to click either "OK" or user will have to click "OK" to "Cancel" to proceed. proceed. <script>alert("Hello World!")</script>  If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false. • <script>confirm(―Sure??")</script>
  • 13. Prompt Box • A prompt box is often used if we want the user to input a value . • When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value. • If the user clicks "OK―, the box returns the input value. If the user clicks "Cancel―, the box returns null. • <script> var name=prompt("Please enter your name","Harry");</script>
  • 14. „if‟ statement • if ( boolean statement ) {…} else {…} • „switch‟ statement • switch ( myVar ) { • case 1: // if myVar is equal to 1 this is executed • break; • case “two”: // if myVar is equal to “two” this is executed • break; • case default: // if none of the cases above are satisfied OR if no • // „break‟ statement are used in the cases above, • // this will be executed • }
  • 15. The For Loop • SYNTAX: for (start; condition; update) {JavaScript Commands} • start is the starting value of the counter. • condition is a Boolean expression that must be true for the loop to continue • update specifies how the counter changes in value each time the command block is executed • Example for (var i=0; i<4; i++) { j++; } • The While Loop • SYNTAX: while (condition) { JavaScript Commands} • condition is a Boolean expression that can be either true or false • Example while (var i<=10) { j++; i++;} • The Do While Loop • SYNTAX: do statement while (condition);
  • 16. • Functions should be defined in the <head> of an HTML page, to ensure that they are loaded first • The syntax for defining a function is: function fname(arg1, …, argN) { statements } • The function may return value. • Any variables declared within the function are local to it. • The syntax for calling a function is just name(arg1, …, argN) • Simple parameters are passed by value, objects are passed by reference • Function names are case-sensitive. • There is no limit to the number of function parameters that a function may contain. •
  • 17. • An object is just a special kind of data, with properties and methods. • Almost everything in JavaScript is an Object: String, Number, Array, Function, image.... Ex document.bgcolor document.write(‖Hello"); • document is the object. is the object. document • bgcolor is the property. method. write is the • We can also create our own objects: • SYNTAX: { name1 : value1 , ... , nameN : valueN } • EXAMPLE: car = {myCar: "Saturn", variant: "Mazda", special: Sales} • Example use: document.write("I own a " + car.myCar); • Using new: • var course = new Object(); • Using a constructor: course.number = "CIT597"; • function Course(n, t) { // best placed in <head> course.teacher = "Dr. Dave"; this.number = n; // keyword "this" is required, this.teacher = t; //not optional } • var course = new Course("CIT597", "Dr. Dave"); •
  • 18. • Events are actions that occur usually as a result of something the user does. For example, clicking a button is an event, as is changing a text field or moving the mouse over a hyperlink. • We write our scripts so they execute by reacting to events within a web browser. • Since events are at the heart of JavaScript programming, we need a way to detect events. We do that by using built-in event handlers … • Eg: Click, change, focus, load, mouseover, mouseout, reset, submit. <input type=―button‖ onClick=―javascript:doButton()‖> • //calls function when button is clicked. <body onLoad=―javascript:init()‖> • //calls function when page is loaded. •
  • 19.
  • 20. • DOM stands for Document Object Model. • It is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document. • The HTML DOM defines a standard for accessing and manipulating HTML documents. • DOM is a tree of Objects • Contents can be modified or deleted • New elements can be created and inserted into the DOM Tree
  • 21. • The document object is the JavaScript interface to the DOM of any HTML page. • Accessing elements: – By name • document.getElementsByTagName(‗td')[indexOfColumn]; • –By ID • document.getElementById('id'); • – Walk the DOM Tree • document.childNodes[0].childNodes[1].childNodes[4]; •
  • 22. • JavaScript provides some limited, persistent storage, called cookies: •– Data is stored in a text file on the client •– name=value •–Multiple values are delimited by a semicolon • Use sparingly. There are limits (generally): •– Up to 300 cookies per browser, 20 cookies per web server, and 4 KB of data per cookie • Don‘t depend on cookies—users can block or delete them.
  • 23. • By default, cookies are destroyed when the browser window is closed, unless we explicitly set the expires attribute. • – To persist a cookie, set the expires attribute to a future date. • – To delete a cookie, set the expires attribute to a past date. • By default, cookies can only be read by the web page that wrote them unless we specify one or more of these attributes: • – path – allows more than one page on the site to read a cookie.(default value: /) • – domain – allows multiple servers to read a cookie. • -name – An identifier by which we reference a particular cookie. • -value – The information we wish to save, in reference to a particular cookie. • -expires – A GMT-formatted date specifying the date (in milliseconds) when a cookie will expire.  SYNTAX to create a cookie: • document.cookie = "username=" + who + ";‖ + "expires=" + expDate.toGMTString();+ ―path=/‖
  • 24. • Difficult because the language is interpreted. • – No compiler errors/warnings. • – Browser will try to run the script, errors and all. • Make each line as granular as possible (use variables). • Use alerts to get values of variables and see which lines are not getting processed. • When testing form validation, set the action attribute to a dummy HTML page—not the server-side form. If you get the page, the script works. • Try add-on like Firebug to detect problem. • JavaScript is not totally platform independent • – Expect different browsers to behave differently • – Check whether the browser supports the functionality or not.