SlideShare a Scribd company logo
Programming on the Web(CSC309F)


     Tutorial 5: JAVASCRIPT
      TA:Wael Abouelsaadat
  WebSite:   http://www.cs.toronto.edu/~wael

   Office-Hour: Friday 12:00-1:00 (SF2110)

        Email: wael@cs.toronto.edu




                                               1
JavaScript

Ø JavaScript vs. JScript:
     § Jscript Homepage:    http://msdn.microsoft.com/scripting/default.htm
     § JavaScript Homepage: http://developer.netscape.com/tech/javascript/index.html

ØJavaScript Built-in Data Types:
    § Boolean (true or false)
    § Null
    § Number ( double-precision 64-bit format)
    § Object (encompassing the Array object)
    § String
    § Undefined

Ø JavaScript Built-in Objects:

                     Array1              Boolean             Date                  Error2
                     EvalError2          Function1           Math                  Number1
                     Object1             RangeError2         ReferenceError2       RegExp 3

                     String1             SyntaxError2        TypeError2            URIError2
                               (1) ECMA Level 1      (2) ECMA Level 2   (3) ECMA Level 3




                                                                                               2
JavaScript Built-in Objects

Ø String Object:
     § Properties:
           • constructor                                    length                                    prototype

     § Methods:
          • charAt( index )                                 charCodeAt([index])                       concat( string2)
              indexOf( SearchString, StartIndex )           lastIndexOf( searchString, StartIndex )   localeCompare( string2 )
              match( regExpression )                        replace( regExpression, replaceString)    slice( startIndex, endIndex )
              split( “delimiterCharacter”, limitInteger )   substr( start, length )                   substring( indexA, indexB )
              toLocaleLowerCase( )                          toLocaleUpperCase( )                      toLowerCase( )
              toUpperCase()                                 toString()                                valueOf()

     § Formatting methods:
          • anchor( “anchorName”),                          blink( )                                  bold( )
              fixed()                                       fontcolor(colorValue)                     fontsize( integer1-7)
              italics()                                     link( locationOrURL)                      big()
              small()                                       strike()                                  sub(), sup()


     § Special inline characters:
           • ” Double quote                                ’ Single quote                            Blackslash
             b Backspace                                   t tab                                    n new line
             r Carriage return                             f form feed




                                                                                                                                      3
JavaScript Built-in Objects

Ø Math Object:
    § Properties:
            • E( Euler’s constant)                  LN2(Natural log of 2)      LN10(natural log of 10)
              LOG2E(log base-2 of E)                LOG10E(log base-10 of E)   PI
              SQRT1_2( square root of 0.5)          SQRT2(square root of 2)

     § Methods:
          • abs( value )                            acos( value )              asin( value )
              atan( value )                         atan2( value1, value2 )    ceil( value )
              cos( value )                          exp( value )               floor( value )
              log( value )                          max( value1, value2 )      min( value1, value2 )
              pow( value1, value2 )                 random( )                  round( value )
              sin( value )                          sqrt( value )              tan( value )


Ø Number Object:
    • Properties:
            • constructor                           MAX_VALUE                  MIN_VALUE
              NaN                                   NEGATIVE_INFINITY          POSITIVE_INIFINITY
              prototype

     § Methods:
          • toExponential( value )                  toFixed( value )           toLocaleString( value )
              toString( value )                     toPrecision( )             valueOf( )




                                                                                                         4
JavaScript Built-in Objects (cont’d)
Ø Boolean Object:
    • Properties:
          • constructor                       prototype

     § Methods:
          • toString( BooleanValue )          valueOf( )


Ø Date Object:
    § Methods:
          • getFullYear( )                    getYear( )                         getMonth( )
            getDate( )                        getDay( )                          getHours( )
            getMinutes( )                     getSeconds( value )                getTime( value )
            getMilliseconds( )                getUTCFullYear( value1, value2 )   getUTCMonth( value1, value2 )
            getUTCDate( value1, value2 )      getUTCDay( )                       getUTCHours( value )
            getUTCMinutes( )                  getUTCSeconds( )                   tgetUTCMilliseconds( )
            setYear( value )                  setFullYear( value )               setMonth( value )
            setDate ( value )                 setHours( value )                  setMinutes( value )
            setSeconds( value )               setMilliseconds( value )           setTime( value )
            setUTCFullYear( value )           setUTCMonth( value )               setUTCDate ( value )
            setUTCHours( value )              setUTCMinutes( value )             setUTCSeconds( value )
            setUTCMilliseconds( value )       getTimezoneOffset( )               toDateString( )
            toGMTString( )                    toLocaleString( )                  toLocateTimeString( )
            toString( )                       toTimeString( )                    toUTCString( )
            parse( “a date string”)           UTC( date values )




                                                                                                           5
JavaScript Built-in Objects (cont’d)
Ø Array Object:
    • Properties:
          • constructor                               prototype

     § Methods:
          • concat( array2 )                          join( SeparatorString )          pop( )
            push( value or Object )                   shift( )                         unshift( )
            reverse( )                                slice( StartIndex , EndIndex )   sort( compareFunction )
            splice( StartIndex, DeleteCount, item )   toLocaleString                   toString( )




                                                                                                                 6
JavaScript Control Structures
Ø If… Else:          var boolChecked = new Boolean( true );
                     if( boolChecked.valueof( ) ){
                     }
Ø for Loops:         var nIndex, nCount = 10;
                     for( var nIndex= 0; nIndex < nCount ; nIndex++ ) {
                         // statements
                     }
Ø while Loops:       var nIndex, nCount = 10;
                     while( nIndex < nCount ) {
                        // statements
                         nIndex++;
                     }
Ø do-while Loops:    var nIndex, nCount = 10;
                     do{
                        // statements
                        nIndex++;
                     } while(nIndex < nCount )
Ø with Statement:    function seeColor( form )
                        with( form.colorsList ){
                           newColor = (options[selectedIndex].text);
                        }
                     }
Øswitch Statement:   switch( nPrice ){
                       case 10: // statements
                                  break;
                       case 20: // statements
                                  break;
                       default: // statements                             7
                     }
JavaScript Operators
Ø Comparison Operators:
         == , != , === (strictly equals), !== (strictly does not equal), > , >=, < , <=

Ø Connubial Operators:
          +, -, *, /, % (module), ++, --, +value, -value

Ø Assignment Operators:
         =, +=, -=, *=, /=, %=, <<=, >=, >>=, >>>=, &=, |=, ^=

Ø Boolean Operators:
          &&, ||, !

Ø Bitwise Operators:
           &, |, ^, ~, <<, >>, >>>

Ø Object Operators:
          delete, in, instanceof, new, this

Ø Other Operators:
          typeof, void




                                                                                          8
JavaScript Global Functions and Statements
Ø Global Functions:
    § decodeURI( “encodedURI” )
    § decodeURIComponent(“encodedURIComponent” )
    § encodeURI( “URIString” )
    § encodeURIComponent( “URIComponentString” )
    § escape( “URIString” )
    § unescape( “escapedURIString” )
    § eval( “string” )                // evaluate any JavaScript statement or expression stored as string
    § isFinite( number )              // checks if number is beyond JavaScript ability to handle
    § isNan( expression )             // tests whether a value is a number or not
    § Number( “string” )              // converts a string to a numeric value
    § parseFloat( “string” )          // converts a string to a float
    § parseInt( “string” , radix )    // converts a string to an integer
    § toString( )                     // returns a string representation
    § unwatch( )                      // for debugging purposes
    § watch( )                        // for debugging purposes

Ø Statements:
     § const                                                      // e.g. const FREEZING_F = 32;
     § var                                                        // e.g.: var temperature = 32;
     § // comments



                                                                                                 9
JavaScript Events
Event         Supported By
OnAbort       Image
OnBlur        Button, Checkbox, FileUpload, Layer, Password,Radio, Reset, Select, Submit, Text, TextArea, Window.
OnChange      Select, text, input elements
OnClick       Select, text, input elements
onDblClick    Document, image button elements, Link
onDragDrop    Window elements
onError       Image, Window
onFocus       Button, Checkbox, FileUpload, Password, Radio, Reset, Select, Submit, Text, TextArea, Window.
onKeyDown     Document, Image, Link, TextArea.
onKeyPress    Document, Image, Link, TextArea
onKeyUp       Document, Image, Link, TextArea
onload        Image, Window.
onMouseDown   Button, Document, Link
onMouseOut    Layer, link, image
onMouseOver   Layer, link, image
onMouseUp     Document, image, button elements, link
onMove        Window
onReset       Form
onResize      Window
onSelect      Text, textarea

onSubmit      Form
                                                                                                                    10
onUnload      Window
JavaScript – Applet Communication
Ø test.html
              <html>
              <head><title>test</title></head>
              <body>
                   <h1>This is a test of applets</h1>
                   <hr></hr>
                   <applet name="testapplet" code="TestApplet.class" height="300" width="300">
                             <param name="text" value="Grizzly Dave!"></param>
                             Text displayed by non-java enabled browsers
                   </applet>
                   <hr></hr>
                   <form>
                             <input type="button“ onclick="alert(document.testapplet.getText())“ value="Get Data From Applet">
                   </form>
              </body>
              </html>
Ø TestApplet.java
              import java.applet.*;
              import java.awt.*;

              public class TestApplet extends Applet {
                 String text = "error";
                 public void init() {
                    text = getParameter("text");
                 }
                 public void paint(Graphics g) {
                  g.drawString(text,50,50);
                 }
                public String getText() {
                  return text;
                }
              }                                                                                                                  11
DOM Hierarchy
                                                                        Window
                                                                  (frame,self,top,parent)




            navigator              screen               history                 document                     location            event




             link         stylesheets              applets             form                 images               plugins         embeds



    anchor                                                                                                                                   all
                        textarea            text              radio            button                reset              select


selection
                                                                                                                                          [elements]
                                                                                                                        option
                                                   password            checkbox             submit


                                                                                                                                             style




                                                                                                                                           12
Sites:

Ø JavaScript
     § http://developer.netscape.com/docs/manuals/javascript.html
     § http://www.gatescript.com/
     § http://www.devguru.com/Technologies/ecmascript/quickref/javascript_intro.html
     § http://webdeveloper.earthweb.com/webjs/
     § http://www.jsworld.com/


Ø Dynamic HTML
    § http://www.dynamicdrive.com/
    § http://www.htmlguru.com/guru.html
    § http://www.w3schools.com/dhtml/




                                                                                       13

More Related Content

What's hot (20)

PDF
深入浅出Jscex
jeffz
 
PDF
Codemash-Clojure.pdf
Howard Lewis Ship
 
PDF
Jscex: Write Sexy JavaScript
jeffz
 
PDF
DevFest Istanbul - a free guided tour of Neo4J
Florent Biville
 
PDF
Scala in Places API
Łukasz Bałamut
 
PDF
Coding in Style
scalaconfjp
 
PPTX
Clojure And Swing
Skills Matter
 
PDF
Grammarware Memes
Eelco Visser
 
PDF
20070329 Java Programing Tips
Shingo Furuyama
 
PDF
Node 관계형 데이터베이스_바인딩
HyeonSeok Choi
 
PDF
Soft Shake Event / A soft introduction to Neo4J
Florent Biville
 
PDF
Dart
anandvns
 
KEY
Breaking the wall
Taras Kalapun
 
PPTX
MongoDB Live Hacking
Tobias Trelle
 
PDF
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
Taro Matsuzawa
 
PDF
Scala for Java programmers
輝 子安
 
ODP
Groovy intro for OUDL
J David Beutel
 
PDF
Scala-对Java的修正和超越
Caoyuan Deng
 
PDF
Mary Had a Little λ (QCon)
Stephen Chin
 
深入浅出Jscex
jeffz
 
Codemash-Clojure.pdf
Howard Lewis Ship
 
Jscex: Write Sexy JavaScript
jeffz
 
DevFest Istanbul - a free guided tour of Neo4J
Florent Biville
 
Scala in Places API
Łukasz Bałamut
 
Coding in Style
scalaconfjp
 
Clojure And Swing
Skills Matter
 
Grammarware Memes
Eelco Visser
 
20070329 Java Programing Tips
Shingo Furuyama
 
Node 관계형 데이터베이스_바인딩
HyeonSeok Choi
 
Soft Shake Event / A soft introduction to Neo4J
Florent Biville
 
Dart
anandvns
 
Breaking the wall
Taras Kalapun
 
MongoDB Live Hacking
Tobias Trelle
 
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
Taro Matsuzawa
 
Scala for Java programmers
輝 子安
 
Groovy intro for OUDL
J David Beutel
 
Scala-对Java的修正和超越
Caoyuan Deng
 
Mary Had a Little λ (QCon)
Stephen Chin
 

Similar to tutorial5 (20)

PDF
楽々Scalaプログラミング
Tomoharu ASAMI
 
PDF
Spark schema for free with David Szakallas
Databricks
 
KEY
Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Hiroki Mizuno
 
PDF
Robust Operations of Kafka Streams
confluent
 
KEY
みゆっき☆Think#7 「本気で学ぶJavascript」
techtalkdwango
 
KEY
第7回みゆっき☆Think 本気で学ぶ JavaScript
Takuya Fujimura
 
PDF
Scala introduction
vito jeng
 
PDF
Meta-objective Lisp @名古屋 Reject 会議
dico_leque
 
PDF
SVGo: a Go Library for SVG generation
Anthony Starks
 
PPTX
Angular2 for Beginners
Oswald Campesato
 
PDF
Java Script Workshop
Dmitry Baranovskiy
 
PDF
Serializing EMF models with Xtext
meysholdt
 
ZIP
Lisp Macros in 20 Minutes (Featuring Clojure)
Phil Calçado
 
PDF
Coding for
David Gelb
 
PDF
MongoDB + node.js で作るソーシャルゲーム
Suguru Namura
 
PDF
Continuation Passing Style and Macros in Clojure - Jan 2012
Leonardo Borges
 
KEY
Command Liner with Scala
なんとか くら
 
PDF
SVGo workshop
Anthony Starks
 
PDF
Spark Summit EU talk by Ted Malaska
Spark Summit
 
PDF
Introduction to Scalding and Monoids
Hugo Gävert
 
楽々Scalaプログラミング
Tomoharu ASAMI
 
Spark schema for free with David Szakallas
Databricks
 
Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Hiroki Mizuno
 
Robust Operations of Kafka Streams
confluent
 
みゆっき☆Think#7 「本気で学ぶJavascript」
techtalkdwango
 
第7回みゆっき☆Think 本気で学ぶ JavaScript
Takuya Fujimura
 
Scala introduction
vito jeng
 
Meta-objective Lisp @名古屋 Reject 会議
dico_leque
 
SVGo: a Go Library for SVG generation
Anthony Starks
 
Angular2 for Beginners
Oswald Campesato
 
Java Script Workshop
Dmitry Baranovskiy
 
Serializing EMF models with Xtext
meysholdt
 
Lisp Macros in 20 Minutes (Featuring Clojure)
Phil Calçado
 
Coding for
David Gelb
 
MongoDB + node.js で作るソーシャルゲーム
Suguru Namura
 
Continuation Passing Style and Macros in Clojure - Jan 2012
Leonardo Borges
 
Command Liner with Scala
なんとか くら
 
SVGo workshop
Anthony Starks
 
Spark Summit EU talk by Ted Malaska
Spark Summit
 
Introduction to Scalding and Monoids
Hugo Gävert
 
Ad

More from tutorialsruby (20)

PDF
&lt;img src="../i/r_14.png" />
tutorialsruby
 
PDF
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
tutorialsruby
 
PDF
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
tutorialsruby
 
PDF
&lt;img src="../i/r_14.png" />
tutorialsruby
 
PDF
&lt;img src="../i/r_14.png" />
tutorialsruby
 
PDF
Standardization and Knowledge Transfer – INS0
tutorialsruby
 
PDF
xhtml_basics
tutorialsruby
 
PDF
xhtml_basics
tutorialsruby
 
PDF
xhtml-documentation
tutorialsruby
 
PDF
xhtml-documentation
tutorialsruby
 
PDF
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
PDF
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
PDF
HowTo_CSS
tutorialsruby
 
PDF
HowTo_CSS
tutorialsruby
 
PDF
BloggingWithStyle_2008
tutorialsruby
 
PDF
BloggingWithStyle_2008
tutorialsruby
 
PDF
cascadingstylesheets
tutorialsruby
 
PDF
cascadingstylesheets
tutorialsruby
 
&lt;img src="../i/r_14.png" />
tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
tutorialsruby
 
&lt;img src="../i/r_14.png" />
tutorialsruby
 
&lt;img src="../i/r_14.png" />
tutorialsruby
 
Standardization and Knowledge Transfer – INS0
tutorialsruby
 
xhtml_basics
tutorialsruby
 
xhtml_basics
tutorialsruby
 
xhtml-documentation
tutorialsruby
 
xhtml-documentation
tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
HowTo_CSS
tutorialsruby
 
HowTo_CSS
tutorialsruby
 
BloggingWithStyle_2008
tutorialsruby
 
BloggingWithStyle_2008
tutorialsruby
 
cascadingstylesheets
tutorialsruby
 
cascadingstylesheets
tutorialsruby
 
Ad

Recently uploaded (20)

PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PPTX
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PPTX
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
Market Insight : ETH Dominance Returns
CIFDAQ
 
PDF
Per Axbom: The spectacular lies of maps
Nexer Digital
 
PDF
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
The Future of Artificial Intelligence (AI)
Mukul
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
Market Insight : ETH Dominance Returns
CIFDAQ
 
Per Axbom: The spectacular lies of maps
Nexer Digital
 
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 

tutorial5

  • 1. Programming on the Web(CSC309F) Tutorial 5: JAVASCRIPT TA:Wael Abouelsaadat WebSite: http://www.cs.toronto.edu/~wael Office-Hour: Friday 12:00-1:00 (SF2110) Email: [email protected] 1
  • 2. JavaScript Ø JavaScript vs. JScript: § Jscript Homepage: http://msdn.microsoft.com/scripting/default.htm § JavaScript Homepage: http://developer.netscape.com/tech/javascript/index.html ØJavaScript Built-in Data Types: § Boolean (true or false) § Null § Number ( double-precision 64-bit format) § Object (encompassing the Array object) § String § Undefined Ø JavaScript Built-in Objects: Array1 Boolean Date Error2 EvalError2 Function1 Math Number1 Object1 RangeError2 ReferenceError2 RegExp 3 String1 SyntaxError2 TypeError2 URIError2 (1) ECMA Level 1 (2) ECMA Level 2 (3) ECMA Level 3 2
  • 3. JavaScript Built-in Objects Ø String Object: § Properties: • constructor length prototype § Methods: • charAt( index ) charCodeAt([index]) concat( string2) indexOf( SearchString, StartIndex ) lastIndexOf( searchString, StartIndex ) localeCompare( string2 ) match( regExpression ) replace( regExpression, replaceString) slice( startIndex, endIndex ) split( “delimiterCharacter”, limitInteger ) substr( start, length ) substring( indexA, indexB ) toLocaleLowerCase( ) toLocaleUpperCase( ) toLowerCase( ) toUpperCase() toString() valueOf() § Formatting methods: • anchor( “anchorName”), blink( ) bold( ) fixed() fontcolor(colorValue) fontsize( integer1-7) italics() link( locationOrURL) big() small() strike() sub(), sup() § Special inline characters: • ” Double quote ’ Single quote Blackslash b Backspace t tab n new line r Carriage return f form feed 3
  • 4. JavaScript Built-in Objects Ø Math Object: § Properties: • E( Euler’s constant) LN2(Natural log of 2) LN10(natural log of 10) LOG2E(log base-2 of E) LOG10E(log base-10 of E) PI SQRT1_2( square root of 0.5) SQRT2(square root of 2) § Methods: • abs( value ) acos( value ) asin( value ) atan( value ) atan2( value1, value2 ) ceil( value ) cos( value ) exp( value ) floor( value ) log( value ) max( value1, value2 ) min( value1, value2 ) pow( value1, value2 ) random( ) round( value ) sin( value ) sqrt( value ) tan( value ) Ø Number Object: • Properties: • constructor MAX_VALUE MIN_VALUE NaN NEGATIVE_INFINITY POSITIVE_INIFINITY prototype § Methods: • toExponential( value ) toFixed( value ) toLocaleString( value ) toString( value ) toPrecision( ) valueOf( ) 4
  • 5. JavaScript Built-in Objects (cont’d) Ø Boolean Object: • Properties: • constructor prototype § Methods: • toString( BooleanValue ) valueOf( ) Ø Date Object: § Methods: • getFullYear( ) getYear( ) getMonth( ) getDate( ) getDay( ) getHours( ) getMinutes( ) getSeconds( value ) getTime( value ) getMilliseconds( ) getUTCFullYear( value1, value2 ) getUTCMonth( value1, value2 ) getUTCDate( value1, value2 ) getUTCDay( ) getUTCHours( value ) getUTCMinutes( ) getUTCSeconds( ) tgetUTCMilliseconds( ) setYear( value ) setFullYear( value ) setMonth( value ) setDate ( value ) setHours( value ) setMinutes( value ) setSeconds( value ) setMilliseconds( value ) setTime( value ) setUTCFullYear( value ) setUTCMonth( value ) setUTCDate ( value ) setUTCHours( value ) setUTCMinutes( value ) setUTCSeconds( value ) setUTCMilliseconds( value ) getTimezoneOffset( ) toDateString( ) toGMTString( ) toLocaleString( ) toLocateTimeString( ) toString( ) toTimeString( ) toUTCString( ) parse( “a date string”) UTC( date values ) 5
  • 6. JavaScript Built-in Objects (cont’d) Ø Array Object: • Properties: • constructor prototype § Methods: • concat( array2 ) join( SeparatorString ) pop( ) push( value or Object ) shift( ) unshift( ) reverse( ) slice( StartIndex , EndIndex ) sort( compareFunction ) splice( StartIndex, DeleteCount, item ) toLocaleString toString( ) 6
  • 7. JavaScript Control Structures Ø If… Else: var boolChecked = new Boolean( true ); if( boolChecked.valueof( ) ){ } Ø for Loops: var nIndex, nCount = 10; for( var nIndex= 0; nIndex < nCount ; nIndex++ ) { // statements } Ø while Loops: var nIndex, nCount = 10; while( nIndex < nCount ) { // statements nIndex++; } Ø do-while Loops: var nIndex, nCount = 10; do{ // statements nIndex++; } while(nIndex < nCount ) Ø with Statement: function seeColor( form ) with( form.colorsList ){ newColor = (options[selectedIndex].text); } } Øswitch Statement: switch( nPrice ){ case 10: // statements break; case 20: // statements break; default: // statements 7 }
  • 8. JavaScript Operators Ø Comparison Operators: == , != , === (strictly equals), !== (strictly does not equal), > , >=, < , <= Ø Connubial Operators: +, -, *, /, % (module), ++, --, +value, -value Ø Assignment Operators: =, +=, -=, *=, /=, %=, <<=, >=, >>=, >>>=, &=, |=, ^= Ø Boolean Operators: &&, ||, ! Ø Bitwise Operators: &, |, ^, ~, <<, >>, >>> Ø Object Operators: delete, in, instanceof, new, this Ø Other Operators: typeof, void 8
  • 9. JavaScript Global Functions and Statements Ø Global Functions: § decodeURI( “encodedURI” ) § decodeURIComponent(“encodedURIComponent” ) § encodeURI( “URIString” ) § encodeURIComponent( “URIComponentString” ) § escape( “URIString” ) § unescape( “escapedURIString” ) § eval( “string” ) // evaluate any JavaScript statement or expression stored as string § isFinite( number ) // checks if number is beyond JavaScript ability to handle § isNan( expression ) // tests whether a value is a number or not § Number( “string” ) // converts a string to a numeric value § parseFloat( “string” ) // converts a string to a float § parseInt( “string” , radix ) // converts a string to an integer § toString( ) // returns a string representation § unwatch( ) // for debugging purposes § watch( ) // for debugging purposes Ø Statements: § const // e.g. const FREEZING_F = 32; § var // e.g.: var temperature = 32; § // comments 9
  • 10. JavaScript Events Event Supported By OnAbort Image OnBlur Button, Checkbox, FileUpload, Layer, Password,Radio, Reset, Select, Submit, Text, TextArea, Window. OnChange Select, text, input elements OnClick Select, text, input elements onDblClick Document, image button elements, Link onDragDrop Window elements onError Image, Window onFocus Button, Checkbox, FileUpload, Password, Radio, Reset, Select, Submit, Text, TextArea, Window. onKeyDown Document, Image, Link, TextArea. onKeyPress Document, Image, Link, TextArea onKeyUp Document, Image, Link, TextArea onload Image, Window. onMouseDown Button, Document, Link onMouseOut Layer, link, image onMouseOver Layer, link, image onMouseUp Document, image, button elements, link onMove Window onReset Form onResize Window onSelect Text, textarea onSubmit Form 10 onUnload Window
  • 11. JavaScript – Applet Communication Ø test.html <html> <head><title>test</title></head> <body> <h1>This is a test of applets</h1> <hr></hr> <applet name="testapplet" code="TestApplet.class" height="300" width="300"> <param name="text" value="Grizzly Dave!"></param> Text displayed by non-java enabled browsers </applet> <hr></hr> <form> <input type="button“ onclick="alert(document.testapplet.getText())“ value="Get Data From Applet"> </form> </body> </html> Ø TestApplet.java import java.applet.*; import java.awt.*; public class TestApplet extends Applet { String text = "error"; public void init() { text = getParameter("text"); } public void paint(Graphics g) { g.drawString(text,50,50); } public String getText() { return text; } } 11
  • 12. DOM Hierarchy Window (frame,self,top,parent) navigator screen history document location event link stylesheets applets form images plugins embeds anchor all textarea text radio button reset select selection [elements] option password checkbox submit style 12
  • 13. Sites: Ø JavaScript § http://developer.netscape.com/docs/manuals/javascript.html § http://www.gatescript.com/ § http://www.devguru.com/Technologies/ecmascript/quickref/javascript_intro.html § http://webdeveloper.earthweb.com/webjs/ § http://www.jsworld.com/ Ø Dynamic HTML § http://www.dynamicdrive.com/ § http://www.htmlguru.com/guru.html § http://www.w3schools.com/dhtml/ 13