WEB APPLICATION PROGRAMMING Computer Science Department Java Script

WEB APPLICATION PROGRAMMING Computer Science Department Java. Script

What is Java. Script? 2 Java. Script is a programming language used to make web pages interactive. Java. Script is Case Sensitive The variables last. Name and lastname, are

Add Java. Script to HTML 3 To embed a Javascript in a Web page, use the element: <script type=“text/javascript”> script commands and comments </script> OR: <script LANGUAGE="Java. Script"></script>

Add Java. Script to HTML 4 To access an external script (. js), use: <script src=“External. js” type=“text/javascript”> </script>

Comments 5 The syntax for a single-line comment is: //comment text The syntax of a multi-line comment is: /*comment text covering several lines*/

Window Object 6 Window : Alrt Prompt confirm

Alrt () 7 alert : window. alert ( " Welcome " ) ; OR alert ( " This is a message " ) ;

Java. Script Popup Boxes 8

Prompt() 9 (window. prompt ( Please enter your name ”, “your name ” ; Example: x = prompt( “Enter your name”, ””); Java. Script statements are separated by semicolons.

Confirm () 10 confirm ("Are you sure you want to save changes ? " ) ; Ok button = True Cancel button = false

Java. Script Popup Boxes 11

Document Object 12 Write <html> <head></head> <body> <script type="text/Java. Script"> document. write("Hello"); </script> </body> </html>

13 document. write ( " Hello " + x ) ;

Max HTML &Java. Script 14 >html> >head< >script LANGUAGE="Java. Script< document. write (“<font color=red> Are you sure to delete? </font>”); document. write ("<p ; ("< document. write ("<center>" + "<input type='button' value=‘yes' >") ; document. write ("<input type='button' value=‘no' > </center>") ; document. write ("</p>") ; </script> </head> </html>

variables 15 var name="Ahmed" ; var name ; name = "Ahmed" ; var x, y, z; var x , y , z = 10 ; x = " Hi " ; y = " Ahmed " ; z=x+""+y;

Java. Script If. . . Else Statements 16 if statement - use this statement to execute some code only if a specified condition is true • if. . . else statement - use this statement to execute some code if the condition is true and another code if the condition is false

Java. Script Switch Statement 17 Use the switch statement to select one of many blocks of code to be executed.

Example 18 var contry ; contry = window. prompt (“Enter the country to know the Capital city ” , country ); switch ( contry ) { case ” Saudi: " document. writeln( “ <h 3>Riyadh </h 3>”); breack ; case ” Egypt: " document. writeln ( “ <h 3> Cairo </h 3>”); breack ; default : document. writeln ( " <h 3>The country doesn’t found in database </h 3>”); }

loop 19 var i=1; while ( i <= 10 ) { document. write ( i ); i ++ ; }

Function 20 function result (a , b ) { c=a+b; return c ; }

index. Of 21 var x = " Hello mohamed. How are you Mohamed " ; var y = x. index. Of (" Mohamed ") ; alert ( y ) ;

Object 22 String object : var name =new String (“ ……. . “); Number object : var x=new Number(numer); Date object : var name=new Date(); get. Date ( ) , get. Hours ( ) , get. Minutes ( ) , get. Seconds ( ) , get. Month ( ) dr. Amal Khalifa, 2014

23 var x=new. Date(); alert ( x. get. Date ( ) ) ; var x = new Date ( ) ; alert ( x. get. Day ( ) ) ; var x=new. Date(); alert ( x. get. Time ( ) ) ;

Writing into HTML output 24

Java. Script Examples. . 25

Java. Script Examples. . 26

Java. Script Examples: 27 On cilck event changes an HTML element:

Java. Script Examples. . 28
- Slides: 28