+ All Categories
Home > Documents > In the Name of Allah ,The Most Gracious, The Most Merciful

In the Name of Allah ,The Most Gracious, The Most Merciful

Date post: 21-Jan-2016
Category:
Upload: phuong
View: 39 times
Download: 0 times
Share this document with a friend
Description:
In the Name of Allah ,The Most Gracious, The Most Merciful. King Khalid University College of Computer and Information System. Web pages Development & Programming. Chapter 5: JavaScript (js). Alaa Alwabel - 2011. What is Javascript?. - PowerPoint PPT Presentation
20
Company LOGO In the Name of Allah ,The Mos Gracious, The Most Merciful King Khalid University College of Computer and Information System Web pages Development & Programming Alaa Alwabel - 2011 Chapter 5: JavaScript (js) 1
Transcript
Page 1: In the Name of Allah ,The Most Gracious,  The Most Merciful

Company

LOGO

In the Name of Allah ,The Most Gracious,

The Most Merciful

King Khalid UniversityCollege of Computer and

Information System

Web pages Development & Programming

Alaa Alwabel - 2011

Chapter 5: JavaScript (js)

1

Page 2: In the Name of Allah ,The Most Gracious,  The Most Merciful

What is Javascript?

2

JavaScript was designed to add interactivity to HTML pages.

JavaScript is a scripting language: A scripting language is a lightweight programming language.

JavaScript is usually embedded directly intoHTML pages

Page 3: In the Name of Allah ,The Most Gracious,  The Most Merciful

What Can JavaScript do?

3

1. JavaScript gives HTML designers a programming tool.

2. JavaScript can react to events.

3. JavaScript can read and write HTML elements.

4. JavaScript can be used to detect the visitor's browser.

5. JavaScript can be used to create cookies.

Page 4: In the Name of Allah ,The Most Gracious,  The Most Merciful

Example

4

html><head><title>JavaScript Page</title></head><body><script type="text/javascript">document.write("<p>Hello world!</p>");document.write(" <p>How are <br/> " +" <i>you</i>?</p> ");</script><p>Here is some static text as well.</p></body></html>

javascript.html

Page 5: In the Name of Allah ,The Most Gracious,  The Most Merciful

Handling browsers that do not support JavaScript

5

•Browsers that do not support JavaScript will display the script as page content. To prevent them from doing this, we may use the HTML comment tag:

<script type="text/javascript"> <!-- document.write("Hello World!") //--> </script>

Page 6: In the Name of Allah ,The Most Gracious,  The Most Merciful

Where to Put the JavaScript

6

Page 7: In the Name of Allah ,The Most Gracious,  The Most Merciful

Variables and If…Else Statement

Variables are used to store data. Declare a Variable You can create a variable with the var statement: var strname = some value You can also create a variable without the var statement: strname = some value

Example: var name=“Reem”

or name =“ Reem”

Example2: var x=5

or x=5

7

Page 8: In the Name of Allah ,The Most Gracious,  The Most Merciful

Conditional Statements

In JavaScript we have the following conditional statements:

if statement - use this statement if you want to execute some code only if a specified condition is true

if...else statement - use this statement if you want to execute some code if the condition is true and another code if the condition is false

if...else if....else statement - use this statement if you want to select one of many blocks of code to be executed.

8

Page 9: In the Name of Allah ,The Most Gracious,  The Most Merciful

If…..else Statement

If you want to execute some code if a condition is true and another code if the condition is not true, use the

if....else statement.

Syntax: if (condition)

{ code to be executed if condition is true }

Note: When comparing variables you must always use two equals signs next to each other (==)!

9

Page 10: In the Name of Allah ,The Most Gracious,  The Most Merciful

Operator

10

Addition+

Subtraction-

Multiplication*

Division/

and&&

or||

not!

is equal to==

is not equal=!

is greater than<

is less than>

Page 11: In the Name of Allah ,The Most Gracious,  The Most Merciful

Popup Boxes

11

Alert Box•An alert box is often used if you want to make sure information comes through to the user.

•When an alert box pops up, the user will have to click "OK" to proceed.

Syntax:alert("sometext")

Page 12: In the Name of Allah ,The Most Gracious,  The Most Merciful

Alert Boxes

12

<html> <head> <script type="text/javascript"> function disp_alert() { alert("I am an alert box!!") } </script> </head> <body> <form action=""> <div> <input type="button" onclick="disp_alert()" value="Display alert box" /> </div> </form> </body> </html

javascript.html

Page 13: In the Name of Allah ,The Most Gracious,  The Most Merciful

Confirm Box

Confirm Box A confirm box is often used if you want the user

to verify or accept something. When a confirm box pops up, the user will have

to click either "OK" or "Cancel" to proceed. If the user clicks "OK", the box returns true. If the

user clicks "Cancel", the box returns false. Syntax: confirm("sometext")

13

Page 14: In the Name of Allah ,The Most Gracious,  The Most Merciful

Confirm Box

14

<html> <head> <script type="text/javascript"> function disp_confirm() { var r=confirm("Press a button") if (r==true) { document.write("You pressed OK!") } else { document.write("You pressed Cancel!") } } </script> </head> <body> <form action=""> <div> <input type="button" onclick="disp_confirm()" value="Display confirm box" /> </div> </form> </body> </html

javascript.html

Page 15: In the Name of Allah ,The Most Gracious,  The Most Merciful

Prompt Box

prompt box is often used if you want the user to input a value before entering a page.

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.

15

Page 16: In the Name of Allah ,The Most Gracious,  The Most Merciful

Prompt Box

16

<html> <head> <script type="text/javascript"> function disp_prompt() { var name=prompt("Please enter your name","Harry Potter") if (name!=null && name!="") { document.write("Hello " + name + "! How are you today?") } } </script> </head> <body> <form action=""> <div> <input type="button" onclick="disp_prompt()" value="Display prompt box" /> </div> </form> </body> </html javascript.html

Page 17: In the Name of Allah ,The Most Gracious,  The Most Merciful

JavaScript Events

By using JavaScript, we have the ability to create dynamic web pages. Events are actions that can be detected by JavaScript.

Examples of events: A mouse click A web page or an image loading Mousing over a hot spot on the web page

Note: Events are normally used in combination with functions, and the function will not be executed before the event occurs!

17

Page 18: In the Name of Allah ,The Most Gracious,  The Most Merciful

onload and onUnload

The onload andonUnload events are triggered when the user enters or leaves the page.

18

<html> <head> <title>Hello/Goodbye page</title>

<script type="text/javascript"> function Hello() { globalName=prompt("Welcome to my page. " + "What is your name?",""); }

function Goodbye() { alert("So long, " + globalName + " come back real soon."); } </script> </head>

<body onload="Hello();" onunload="Goodbye();"> <p>Whatever text appears in the page.</p> </body></html>

Page 19: In the Name of Allah ,The Most Gracious,  The Most Merciful

onMouseOver and onMouseOut

19

<html> <head>

</head> <body> <a href="http://www.w3schools.com" onmouseover="alert('An onMouseOver event');"> <img src="w3schools.gif" width="100" height="30"> </a> </body> </html>

javascript.html

Page 20: In the Name of Allah ,The Most Gracious,  The Most Merciful

Js- Guideline

JavaScript is case sensitive JavaScript ignores extra spaces You can add comments to your script by

using two slashes //. break up a code line within a text string

with a backslash Ex. document.write("Hello \

World!")

20


Recommended