SlideShare una empresa de Scribd logo
1 de 24
Making dynamic pages with
javascript

            Lecture 1
Java script
    java versus javascript
    Javascript is a scripting language that will
    allow you to add real programming to your
    webpages.
     Its not stand alone language as java.
uses for javascript
   Browser Detection
    Detecting the browser used by a visitor at your page. Depending on the
    browser, another page specifically designed for that browser can then
    be loaded.
   Cookies
    Storing information on the visitor's computer, then retrieving this
    information automatically next time the user visits your page. This
    technique is called "cookies".
   Control Browsers
    Opening pages in customized windows, where you specify if the
    browser's buttons, menu line, status line or whatever should be present.

   Validate Forms
    Validating inputs to fields before submitting a form.
    An example would be validating the entered email address to see if it
    has an @ in it, since if not, it's not a valid address.
Position of script tag
1.   Internal
        Between the head tag          / body tag
            What is the different between the scripting between head tag and
             between body tag?
        In the tag itself
            example <p onclick=“ alert(‘good’)”> text </p>


2.   External
     <HTML>                                     One
     <Head>                                    quote
         <SCRIPT LANGUAGE="JavaScript" src=“jfile.js"></SCRIPT>
     </Head>
     <Body>

     </Body>
     </HTML>
Components of javascript
1.   <script> tag
2.   Objects
           ( window, document, form)
1.   Properties
           document.color
1.   Methods
          document.write( )
          document.write( string)
1.   Variables
         var name=“ ali”
         var age=30
1.   Operators and expression
        + ,- , % ,/ …..
.Cont
6.   Statements
            If - If … else
            For
            while
7.   Event handlers.
            KB events: onkeydown – onkeyup- onkeypress
            Mouse events : onmousemove – onmouseover-
             onmousedown- onmouseout- onmouseup- onclick-
             ondblclick
            Load & unload
              Its specified in the <body> tag.
              <body onload=“……”>
Script tag
 <SCRIPT LANGUAGE="JavaScript">
    <!--           Comment tag

         document.write ("Hello World");
     //-->                            code
 </SCRIPT>
Notes:
 Its necessary to but the code between
  comment tag. Why?
 Case sensitive write (ex. document.Write <> document.write)
   Comment statement            (//    or /*      */)
output methods
1.   alert
2.   Write
3.   Print
alert
   alert (“ text”) =      window.alert(“ text”)
   Ex.
       In the tag       :<TagName event=”code statement"></TagName>

           Example :   <p onclick= “ alert(‘ click is occurred’) “ > click </p>

      Using script tag in the head
       <head>
            <SCRIPT LANGUAGE="JavaScript">
                                                               Function
             <!--
                                                                without
                    function demo()
                                                               parameter
                   {
                     alert ("Hello World");
                   }                                    Calling
             //-->                                     function
           </SCRIPT>                                 when event
     </head>                                         is occurred
    Calling:
    <p onclick=“ demo( ) “ > click </p>
Write method
   Examples:
       documet.write(“hello”)
       document.write("<font color=ff0000>
        red text </font>”)
       document.write("<font color=ff0000>
        red text </font> <br> <font
        color=00ff00> green text </font>”)


       Notes:
         Use tags within document
( )Newline in write( ) and alert


document.write(" ppu <br> graphics")
 alert(" are you sure n press OK" )
Print
    window.print()
Input methods
1.       Confirm
2.       Prompt

        confirm
         One of window methods as alert. It return value false/true by
          contrast of alert.
         confirm(“ message ");
          or
         window.confirm(“ message");

          to show the result:
                Alert( confirm (message) )
prompt
   Window method that pass a message to user
    (undefined is default value)
   Prompt( “message”, ”default value”)




   Alert(prompt(…….))
variables
   Types of variables:
       String
       Numbers
       Boolean
       Null
   Naming variables
       Ex    these variable names are correct
            Address1
            A4xb5
            lastName
            _firstName
            parent_Name
       Not correct
            1stName
            ?subName
            last name
            @ userID
Declaration/assignment
   var firstName;
   var firstName, lastName, userID;
   var firstName, lastName = “ali", userID = 13;

   assignment
       var stname;
        stname = "Ahmed“;
cont.

<script>
 function demo( )
{
    var username = ”ali";
    alert("welcomen"+username);
  }
</script>

- improve this code in order to accept your name from
the KB.
Conditional statement
   If (condition) {…..}
   If (condition)
            {……}
       Else
            { ……}
   If (condition)
            {……}
       Else if ( )
              { ……}
example
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
var age, name;
name = prompt(“what’s your name”,”enter your name here");
age=prompt(“what’s your age?”,”enter your age here");
document.write( "<b> welcome : </b>" + name + "<br>" );

If ( age<40)
document.write( "<b> you still youth : </b>" + age+ "<br>"
     +”is your age”);
document.write( "<b> you are experienced person : </b>" + age +
     "<br>" + ”is your age”);

//-->
</SCRIPT>
</HEAD>
switch
switch(value/expression) {
case " val1" :

break;
case " val2 " :

break;
case " val3 " :
break;
.
.
default :
example
var num = 4;
switch( num )
  { case 1 :
           alert( " num is n one " );
           break;
    case 2 :
           alert( " num is n two " );
             break;
    case 3 :
          alert( ” num is n three " );
          break;
default :
         alert( " num is " + num );
break;
}
Iteration
   For
   While

   Print your name four times, each one in a
    separate line.
    var x = 0;
     for( i=1; i<5 ; i++ )
      {
      document.write( “ali” <br> )
      }
while
1- var i = 0;
   while( i<5 )
   {
     document.write( “ali” + "<br>" );
     i++;
  }
2-
var userPassword = "123";
var password = prompt(“enter password", “password ");
while( password != userPassword )
{
   alert( “ wrong try again " );
  password = prompt(“enter password", “password ");
}
Alert (“its correct”);
Good site
   http://www.jsmadeeasy.com/javascripts/Pull%20Down%20Su
   http://www.yourhtmlsource.com/javascript/
   http://www.webteacher.com/javascript/ch01.html

Más contenido relacionado

La actualidad más candente

Java script frame window
Java script frame windowJava script frame window
Java script frame window
H K
 

La actualidad más candente (20)

Backbone js
Backbone jsBackbone js
Backbone js
 
Java Script
Java ScriptJava Script
Java Script
 
Why ruby
Why rubyWhy ruby
Why ruby
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery Basics
 
Web 11 | AJAX + JSON + PHP
Web 11 | AJAX + JSON + PHPWeb 11 | AJAX + JSON + PHP
Web 11 | AJAX + JSON + PHP
 
Java script frame window
Java script frame windowJava script frame window
Java script frame window
 
Web 6 | JavaScript DOM
Web 6 | JavaScript DOMWeb 6 | JavaScript DOM
Web 6 | JavaScript DOM
 
jQuery Best Practice
jQuery Best Practice jQuery Best Practice
jQuery Best Practice
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
Ruby - Design patterns tdc2011
Ruby - Design patterns tdc2011Ruby - Design patterns tdc2011
Ruby - Design patterns tdc2011
 
Handlebars
HandlebarsHandlebars
Handlebars
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com Backbone
 
Wt unit 2 ppts client side technology
Wt unit 2 ppts client side technologyWt unit 2 ppts client side technology
Wt unit 2 ppts client side technology
 
GDI Seattle - Intro to JavaScript Class 4
GDI Seattle - Intro to JavaScript Class 4GDI Seattle - Intro to JavaScript Class 4
GDI Seattle - Intro to JavaScript Class 4
 
Backbone - TDC 2011 Floripa
Backbone - TDC 2011 FloripaBackbone - TDC 2011 Floripa
Backbone - TDC 2011 Floripa
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 
前端概述
前端概述前端概述
前端概述
 
Angular JS2 Training Session #1
Angular JS2 Training Session #1Angular JS2 Training Session #1
Angular JS2 Training Session #1
 
Handlebars.js
Handlebars.jsHandlebars.js
Handlebars.js
 
Laravel 로 배우는 서버사이드 #5
Laravel 로 배우는 서버사이드 #5Laravel 로 배우는 서버사이드 #5
Laravel 로 배우는 서버사이드 #5
 

Similar a Javascript1

10. session 10 loops and arrays
10. session 10   loops and arrays10. session 10   loops and arrays
10. session 10 loops and arrays
Phúc Đỗ
 
1472251766_demojavascriptppt (1).ppt
1472251766_demojavascriptppt (1).ppt1472251766_demojavascriptppt (1).ppt
1472251766_demojavascriptppt (1).ppt
ictlab3
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 

Similar a Javascript1 (20)

JavaScript
JavaScriptJavaScript
JavaScript
 
Java script
Java scriptJava script
Java script
 
Java scipt
Java sciptJava scipt
Java scipt
 
Javascript 1
Javascript 1Javascript 1
Javascript 1
 
Js mod1
Js mod1Js mod1
Js mod1
 
Javascript
JavascriptJavascript
Javascript
 
1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentals
 
Single page webapps & javascript-testing
Single page webapps & javascript-testingSingle page webapps & javascript-testing
Single page webapps & javascript-testing
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript Misunderstood
 
10. session 10 loops and arrays
10. session 10   loops and arrays10. session 10   loops and arrays
10. session 10 loops and arrays
 
Java script
Java scriptJava script
Java script
 
JavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & Implementation
 
1472251766_demojavascriptppt (1).ppt
1472251766_demojavascriptppt (1).ppt1472251766_demojavascriptppt (1).ppt
1472251766_demojavascriptppt (1).ppt
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript
 
2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript
 
JavaScript Training
JavaScript TrainingJavaScript Training
JavaScript Training
 

Último

Último (20)

Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
IPL Online Quiz by Pragya; Question Set.
IPL Online Quiz by Pragya; Question Set.IPL Online Quiz by Pragya; Question Set.
IPL Online Quiz by Pragya; Question Set.
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the life
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 

Javascript1

  • 1. Making dynamic pages with javascript Lecture 1
  • 2. Java script  java versus javascript Javascript is a scripting language that will allow you to add real programming to your webpages. Its not stand alone language as java.
  • 3. uses for javascript  Browser Detection Detecting the browser used by a visitor at your page. Depending on the browser, another page specifically designed for that browser can then be loaded.  Cookies Storing information on the visitor's computer, then retrieving this information automatically next time the user visits your page. This technique is called "cookies".  Control Browsers Opening pages in customized windows, where you specify if the browser's buttons, menu line, status line or whatever should be present.  Validate Forms Validating inputs to fields before submitting a form. An example would be validating the entered email address to see if it has an @ in it, since if not, it's not a valid address.
  • 4. Position of script tag 1. Internal  Between the head tag / body tag  What is the different between the scripting between head tag and between body tag?  In the tag itself  example <p onclick=“ alert(‘good’)”> text </p> 2. External <HTML> One <Head> quote <SCRIPT LANGUAGE="JavaScript" src=“jfile.js"></SCRIPT> </Head> <Body> </Body> </HTML>
  • 5. Components of javascript 1. <script> tag 2. Objects ( window, document, form) 1. Properties document.color 1. Methods document.write( ) document.write( string) 1. Variables var name=“ ali” var age=30 1. Operators and expression  + ,- , % ,/ …..
  • 6. .Cont 6. Statements  If - If … else  For  while 7. Event handlers.  KB events: onkeydown – onkeyup- onkeypress  Mouse events : onmousemove – onmouseover- onmousedown- onmouseout- onmouseup- onclick- ondblclick  Load & unload  Its specified in the <body> tag.  <body onload=“……”>
  • 7. Script tag  <SCRIPT LANGUAGE="JavaScript"> <!-- Comment tag document.write ("Hello World"); //--> code </SCRIPT> Notes:  Its necessary to but the code between comment tag. Why?  Case sensitive write (ex. document.Write <> document.write)  Comment statement (// or /* */)
  • 8. output methods 1. alert 2. Write 3. Print
  • 9. alert  alert (“ text”) = window.alert(“ text”)  Ex.  In the tag :<TagName event=”code statement"></TagName>  Example : <p onclick= “ alert(‘ click is occurred’) “ > click </p>  Using script tag in the head <head> <SCRIPT LANGUAGE="JavaScript"> Function <!-- without function demo() parameter { alert ("Hello World"); } Calling //--> function </SCRIPT> when event </head> is occurred Calling: <p onclick=“ demo( ) “ > click </p>
  • 10. Write method  Examples:  documet.write(“hello”)  document.write("<font color=ff0000> red text </font>”)  document.write("<font color=ff0000> red text </font> <br> <font color=00ff00> green text </font>”)  Notes:  Use tags within document
  • 11. ( )Newline in write( ) and alert document.write(" ppu <br> graphics")  alert(" are you sure n press OK" )
  • 12. Print  window.print()
  • 13. Input methods 1. Confirm 2. Prompt  confirm  One of window methods as alert. It return value false/true by contrast of alert.  confirm(“ message "); or window.confirm(“ message");  to show the result: Alert( confirm (message) )
  • 14. prompt  Window method that pass a message to user (undefined is default value)  Prompt( “message”, ”default value”)  Alert(prompt(…….))
  • 15. variables  Types of variables:  String  Numbers  Boolean  Null  Naming variables  Ex these variable names are correct  Address1  A4xb5  lastName  _firstName  parent_Name  Not correct  1stName  ?subName  last name  @ userID
  • 16. Declaration/assignment  var firstName;  var firstName, lastName, userID;  var firstName, lastName = “ali", userID = 13;  assignment  var stname;  stname = "Ahmed“;
  • 17. cont. <script> function demo( ) { var username = ”ali"; alert("welcomen"+username); } </script> - improve this code in order to accept your name from the KB.
  • 18. Conditional statement  If (condition) {…..}  If (condition) {……} Else { ……}  If (condition) {……} Else if ( ) { ……}
  • 19. example <HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- var age, name; name = prompt(“what’s your name”,”enter your name here"); age=prompt(“what’s your age?”,”enter your age here"); document.write( "<b> welcome : </b>" + name + "<br>" ); If ( age<40) document.write( "<b> you still youth : </b>" + age+ "<br>" +”is your age”); document.write( "<b> you are experienced person : </b>" + age + "<br>" + ”is your age”); //--> </SCRIPT> </HEAD>
  • 20. switch switch(value/expression) { case " val1" : break; case " val2 " : break; case " val3 " : break; . . default :
  • 21. example var num = 4; switch( num ) { case 1 : alert( " num is n one " ); break; case 2 : alert( " num is n two " ); break; case 3 : alert( ” num is n three " ); break; default : alert( " num is " + num ); break; }
  • 22. Iteration  For  While  Print your name four times, each one in a separate line. var x = 0; for( i=1; i<5 ; i++ ) { document.write( “ali” <br> ) }
  • 23. while 1- var i = 0; while( i<5 ) { document.write( “ali” + "<br>" ); i++; } 2- var userPassword = "123"; var password = prompt(“enter password", “password "); while( password != userPassword ) { alert( “ wrong try again " ); password = prompt(“enter password", “password "); } Alert (“its correct”);
  • 24. Good site  http://www.jsmadeeasy.com/javascripts/Pull%20Down%20Su  http://www.yourhtmlsource.com/javascript/  http://www.webteacher.com/javascript/ch01.html