SlideShare a Scribd company logo
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Hidaya Institute of
Science &
Technology
www.histpk.org
A Division of Hidaya Trust, Pakistan
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
JAVASCRIPT
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
DIALOG BOX
Alert Dialog Box:
•An alert dialog box is mostly used to give a warning message to
the users. Like if one input field requires to enter some text but
user does not enter that field then as a part of validation you
can use alert box to give warning message
alert(“text”);
Confirmation Dialog Box:
•A confirmation dialog box is mostly used to take user's consent on any
option. It displays a dialog box with two buttons: OK and Cancel.
•If the user clicks on OK button the window method confirm() will
return true. If the user clicks on the Cancel button confirm() returns
false. You can use confirmation dialog box
confirm(“Message");
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
DIALOG BOX
•Prompt Dialog Box:
•The prompt dialog box is very useful when you want to pop-up
a text box to get user input. Thus it enable you to interact with
the user. The user needs to fill in the field and then click OK.
•This dialog box is displayed using a method
called prompt() which takes two parameters (i) A label which
you want to display in the text box (ii) A default string to display
in the text box.
•This dialog box with two buttons: OK and Cancel. If the user
clicks on OK button the window method prompt() will return
entered value from the text box. If the user clicks on the Cancel
button the window method prompt() returns null.
•prompt(“Message At top", “Name In Field");
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
FUNCTIONS
•A function is a group of reusable code which can be called
anywhere in your program. This eliminates the need of writing
same code again and again.
•Help programmers to write modular code.
•Can easily divide your big program in a number of small and
manageable functions.
•Like any other advance programming language, JavaScript also
supports all the features necessary to write modular code using
functions.
•You must have seen functions like alert() and write(), We are
using these function again and again but they have been written
in core JavaScript only once.
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
FUNCTIONS
•The most common way to define a function in JavaScript is by using
the function keyword, followed by a unique function name, a list of
parameters (that might be empty), and a statement block surrounded
by curly braces.
•The basic syntax is shown here:
function functionname(parameter-list)
{
statements
}
Calling a Function:
•To invoke a function somewhere later in the script, you would simple
need to write the name of that function as follows:
functionname();
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
FUNCTIONS
Function Parameters:
•There is a facility to pass different parameters while calling a function.
•These passed parameters can be captured inside the function and any
manipulation can be done over those parameters.
•A function can take multiple parameters separated by comma.
function functionname(para1,para2)
{
statements
}
The return Statement:
A JavaScript function can have an optional return statement. This is
required if you want to return a value from a function. This statement
should be the last statement in a function.
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
EVENTS IN JAVASCRIPT
•JavaScript's interaction with HTML is handled through events
that occur when the user or browser manipulates a page.
•When the page loads, that is an event.
•When the user clicks a button, that click, too, is an event.
• Another example of events are like:
• pressing any key
• closing window
• resizing window.
•Developers can use these events to execute JavaScript coded
responses, which cause buttons to close windows, messages to
be displayed to users, data to be validated, and virtually any
other type of response imaginable to occur.
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
HTML 4 STANDARD EVENTS
Event Value Description
onchange script Script runs when the element changes
onsubmit script Script runs when the form is submitted
onreset script Script runs when the form is reset
onselect script Script runs when the element is selected
onblur script Script runs when the element loses focus
onfocus script Script runs when the element gets focus
onkeydown script Script runs when key is pressed
onkeypress script Script runs when key is pressed and released
onkeyup script Script runs when key is released
onclick script Script runs when a mouse click
ondblclick script Script runs when a mouse double-click
onmousedown script Script runs when mouse button is pressed
onmousemove script Script runs when mouse pointer moves
onmouseout script Script runs when mouse pointer moves out of an element
onmouseover script Script runs when mouse pointer moves over an element
onmouseup script Script runs when mouse button is released
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
DOCUMENT OBJECT MODEL
•Every web page resides inside a browser window which can be considered as an object.
•A Document object represents the HTML document that is displayed in that window.
•The Document object has various properties that refer to other objects which allow access
to and modification of document content.
•The way that document content is accessed and modified is called the Document Object
Model, or DOM. The Objects are organized in a hierarchy.
• This hierarchical structure applies to the organization of objects in a Web document.
•Window object: Top of the hierarchy. It is the outmost element of the object hierarchy.
•Document object: Each HTML document that gets loaded into a window becomes a
document object. The document contains the content of the page.
•Form object: Everything enclosed in the <form>...</form> tags sets the form object.
•Form control elements: The form object contains all the elements defined for that object
such as text fields, buttons, radio buttons, and checkboxes.
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org

More Related Content

PPTX
Presentation
PPT
String functions and operations
PPTX
Dom in javascript
PPT
Java script lecture 1
PPTX
Css presentation lecture 1
PPT
PHP array 2
PPTX
Css presentation lecture 3
PPTX
Dreamweaver cs6
Presentation
String functions and operations
Dom in javascript
Java script lecture 1
Css presentation lecture 1
PHP array 2
Css presentation lecture 3
Dreamweaver cs6

Viewers also liked (16)

PPT
Javascript lecture 3
PPT
Web forms and html lecture Number 4
PPT
String functions and operations
PPTX
Css presentation lecture 4
PPTX
Sessions in php
PPT
Functions in php
PPTX
PHP array 1
PPT
String functions and operations
PPT
Javascript lecture 4
PPT
Form validation with built in functions
PPT
Form validation server side
PPTX
loops and branches
PPT
Web forms and html lecture Number 3
PPTX
introduction to programmin
PPT
Form validation client side
PPT
Web forms and html lecture Number 2
Javascript lecture 3
Web forms and html lecture Number 4
String functions and operations
Css presentation lecture 4
Sessions in php
Functions in php
PHP array 1
String functions and operations
Javascript lecture 4
Form validation with built in functions
Form validation server side
loops and branches
Web forms and html lecture Number 3
introduction to programmin
Form validation client side
Web forms and html lecture Number 2
Ad

Similar to Javascript 2 (20)

PPTX
Learn Javascript Basics
PDF
Hsc IT Chap 3. Advanced javascript-1.pdf
PPTX
INTERNSHIP PPT - INFOLABZ.pptx
PPTX
216170316007.pptx
PDF
Google Assistant Revolution
PPTX
HNDIT1022 Week 08, 09 10 Theory web .pptx
PPTX
Make Mobile Apps Quickly
PDF
Android Jump Start
PPT
Free and Open Source Software
DOC
Raja3Years
PDF
Done in 60 seconds - Creating Web 2.0 applications made easy
PDF
Techjoomla Infrastructure Extensions - Adding an Enterprise Layer to Joomla!
PPTX
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
PPTX
Introduction to JavaScript, functions, DOM
KEY
MAST Portal: drivers and recommendations
PPTX
Joget Workflow v6 Training Slides - 8 - Designing your First Userview
PPTX
Mychoice -classified site for buying, selling, rent etc
PPTX
Basic iOS Training with SWIFT - Part 4
PPTX
JavaScript: Implementations And Applications
PPTX
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Learn Javascript Basics
Hsc IT Chap 3. Advanced javascript-1.pdf
INTERNSHIP PPT - INFOLABZ.pptx
216170316007.pptx
Google Assistant Revolution
HNDIT1022 Week 08, 09 10 Theory web .pptx
Make Mobile Apps Quickly
Android Jump Start
Free and Open Source Software
Raja3Years
Done in 60 seconds - Creating Web 2.0 applications made easy
Techjoomla Infrastructure Extensions - Adding an Enterprise Layer to Joomla!
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Introduction to JavaScript, functions, DOM
MAST Portal: drivers and recommendations
Joget Workflow v6 Training Slides - 8 - Designing your First Userview
Mychoice -classified site for buying, selling, rent etc
Basic iOS Training with SWIFT - Part 4
JavaScript: Implementations And Applications
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Ad

More from Mudasir Syed (20)

PPT
Error reporting in php
PPT
Cookies in php lecture 2
PPT
Cookies in php lecture 1
PPTX
PPT
Reporting using FPDF
PPT
Oop in php lecture 2
PPT
Oop in php lecture 2
PPT
Filing system in PHP
PPT
Time manipulation lecture 2
PPT
Time manipulation lecture 1
PPT
Php Mysql
PPT
Adminstrating Through PHPMyAdmin
PPT
Sql select
PPT
PHP mysql Sql
PPT
PHP mysql Mysql joins
PPTX
PHP mysql Introduction database
PPT
PHP mysql Installing my sql 5.1
PPT
PHP mysql Er diagram
PPT
PHP mysql Database normalizatin
PPT
PHP mysql Aggregate functions
Error reporting in php
Cookies in php lecture 2
Cookies in php lecture 1
Reporting using FPDF
Oop in php lecture 2
Oop in php lecture 2
Filing system in PHP
Time manipulation lecture 2
Time manipulation lecture 1
Php Mysql
Adminstrating Through PHPMyAdmin
Sql select
PHP mysql Sql
PHP mysql Mysql joins
PHP mysql Introduction database
PHP mysql Installing my sql 5.1
PHP mysql Er diagram
PHP mysql Database normalizatin
PHP mysql Aggregate functions

Recently uploaded (20)

PDF
Pre independence Education in Inndia.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Business Ethics Teaching Materials for college
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PPTX
Introduction and Scope of Bichemistry.pptx
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
Pre independence Education in Inndia.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Open Quiz Monsoon Mind Game Prelims.pptx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
O7-L3 Supply Chain Operations - ICLT Program
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Business Ethics Teaching Materials for college
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
UPPER GASTRO INTESTINAL DISORDER.docx
human mycosis Human fungal infections are called human mycosis..pptx
Renaissance Architecture: A Journey from Faith to Humanism
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
Cell Structure & Organelles in detailed.
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
The Final Stretch: How to Release a Game and Not Die in the Process.
Open Quiz Monsoon Mind Game Final Set.pptx
Introduction and Scope of Bichemistry.pptx
Cardiovascular Pharmacology for pharmacy students.pptx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf

Javascript 2

  • 1. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Hidaya Institute of Science & Technology www.histpk.org A Division of Hidaya Trust, Pakistan
  • 2. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org JAVASCRIPT
  • 3. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org DIALOG BOX Alert Dialog Box: •An alert dialog box is mostly used to give a warning message to the users. Like if one input field requires to enter some text but user does not enter that field then as a part of validation you can use alert box to give warning message alert(“text”); Confirmation Dialog Box: •A confirmation dialog box is mostly used to take user's consent on any option. It displays a dialog box with two buttons: OK and Cancel. •If the user clicks on OK button the window method confirm() will return true. If the user clicks on the Cancel button confirm() returns false. You can use confirmation dialog box confirm(“Message");
  • 4. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org DIALOG BOX •Prompt Dialog Box: •The prompt dialog box is very useful when you want to pop-up a text box to get user input. Thus it enable you to interact with the user. The user needs to fill in the field and then click OK. •This dialog box is displayed using a method called prompt() which takes two parameters (i) A label which you want to display in the text box (ii) A default string to display in the text box. •This dialog box with two buttons: OK and Cancel. If the user clicks on OK button the window method prompt() will return entered value from the text box. If the user clicks on the Cancel button the window method prompt() returns null. •prompt(“Message At top", “Name In Field");
  • 5. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org FUNCTIONS •A function is a group of reusable code which can be called anywhere in your program. This eliminates the need of writing same code again and again. •Help programmers to write modular code. •Can easily divide your big program in a number of small and manageable functions. •Like any other advance programming language, JavaScript also supports all the features necessary to write modular code using functions. •You must have seen functions like alert() and write(), We are using these function again and again but they have been written in core JavaScript only once.
  • 6. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org FUNCTIONS •The most common way to define a function in JavaScript is by using the function keyword, followed by a unique function name, a list of parameters (that might be empty), and a statement block surrounded by curly braces. •The basic syntax is shown here: function functionname(parameter-list) { statements } Calling a Function: •To invoke a function somewhere later in the script, you would simple need to write the name of that function as follows: functionname();
  • 7. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org FUNCTIONS Function Parameters: •There is a facility to pass different parameters while calling a function. •These passed parameters can be captured inside the function and any manipulation can be done over those parameters. •A function can take multiple parameters separated by comma. function functionname(para1,para2) { statements } The return Statement: A JavaScript function can have an optional return statement. This is required if you want to return a value from a function. This statement should be the last statement in a function.
  • 8. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org EVENTS IN JAVASCRIPT •JavaScript's interaction with HTML is handled through events that occur when the user or browser manipulates a page. •When the page loads, that is an event. •When the user clicks a button, that click, too, is an event. • Another example of events are like: • pressing any key • closing window • resizing window. •Developers can use these events to execute JavaScript coded responses, which cause buttons to close windows, messages to be displayed to users, data to be validated, and virtually any other type of response imaginable to occur.
  • 9. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org HTML 4 STANDARD EVENTS Event Value Description onchange script Script runs when the element changes onsubmit script Script runs when the form is submitted onreset script Script runs when the form is reset onselect script Script runs when the element is selected onblur script Script runs when the element loses focus onfocus script Script runs when the element gets focus onkeydown script Script runs when key is pressed onkeypress script Script runs when key is pressed and released onkeyup script Script runs when key is released onclick script Script runs when a mouse click ondblclick script Script runs when a mouse double-click onmousedown script Script runs when mouse button is pressed onmousemove script Script runs when mouse pointer moves onmouseout script Script runs when mouse pointer moves out of an element onmouseover script Script runs when mouse pointer moves over an element onmouseup script Script runs when mouse button is released
  • 10. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org DOCUMENT OBJECT MODEL •Every web page resides inside a browser window which can be considered as an object. •A Document object represents the HTML document that is displayed in that window. •The Document object has various properties that refer to other objects which allow access to and modification of document content. •The way that document content is accessed and modified is called the Document Object Model, or DOM. The Objects are organized in a hierarchy. • This hierarchical structure applies to the organization of objects in a Web document. •Window object: Top of the hierarchy. It is the outmost element of the object hierarchy. •Document object: Each HTML document that gets loaded into a window becomes a document object. The document contains the content of the page. •Form object: Everything enclosed in the <form>...</form> tags sets the form object. •Form control elements: The form object contains all the elements defined for that object such as text fields, buttons, radio buttons, and checkboxes.
  • 11. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
  • 12. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org