Presentation is loading. Please wait.

Presentation is loading. Please wait.

WEB APPLICATION PROGRAMMING

Similar presentations


Presentation on theme: "WEB APPLICATION PROGRAMMING"— Presentation transcript:

1 WEB APPLICATION PROGRAMMING
Computer Science Department JavaScript

2 What is JavaScript? JavaScript is a programming language used to make web pages interactive. JavaScript is Case Sensitive The variables lastName and lastname, are two different variables.

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

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

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

6 Window Object Window : Alrt Prompt confirm

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

8 JavaScript Popup Boxes

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

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

11 JavaScript Popup Boxes

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

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

14 Max HTML &JavaScript <html> >head< >script LANGUAGE="JavaScript< 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>

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

16 JavaScript If...Else Statements
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

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

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

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

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

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

22 Object String object : var name =new String (“ ……..“); Number object :
var x=new Number(numer); Date object : var name=new Date(); getDate ( ) , getHours ( ) , getMinutes ( ) , getSeconds ( ) , getMonth ( ) dr. Amal Khalifa, 2014

23 var x=newDate(); alert ( x.getDate ( ) ) ; var x = new Date ( ) ; alert ( x.getDay ( ) ) ; alert ( x.getTime ( ) ) ;

24 Writing into HTML output

25 JavaScript Examples..

26 JavaScript Examples..

27 JavaScript Examples: On cilck event changes an HTML element:

28 JavaScript Examples..


Download ppt "WEB APPLICATION PROGRAMMING"

Similar presentations


Ads by Google