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

Viewers also liked (16)

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

Similar to Javascript 2 (20)

PPTX
Learn Javascript Basics
Khushiar
 
PDF
Hsc IT Chap 3. Advanced javascript-1.pdf
AAFREEN SHAIKH
 
PPTX
INTERNSHIP PPT - INFOLABZ.pptx
DevChaudhari15
 
PPTX
216170316007.pptx
DevChaudhari15
 
PDF
Google Assistant Revolution
Rafael Casuso Romate
 
PPTX
HNDIT1022 Week 08, 09 10 Theory web .pptx
IsuriUmayangana
 
PPTX
Make Mobile Apps Quickly
Gil Irizarry
 
PDF
Android Jump Start
Haim Michael
 
PPT
Free and Open Source Software
Moinuddin Ahmed
 
DOC
Raja3Years
Raja Ravichandran
 
PDF
Done in 60 seconds - Creating Web 2.0 applications made easy
Roel Hartman
 
PDF
Techjoomla Infrastructure Extensions - Adding an Enterprise Layer to Joomla!
Parth Lawate
 
PPTX
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Chris Laning
 
PPTX
Introduction to JavaScript, functions, DOM
LikhithaBrunda
 
KEY
MAST Portal: drivers and recommendations
Alberto Conti
 
PPTX
Joget Workflow v6 Training Slides - 8 - Designing your First Userview
Joget Workflow
 
PPTX
Mychoice -classified site for buying, selling, rent etc
Nikhil Palyekar
 
PPTX
Basic iOS Training with SWIFT - Part 4
Manoj Ellappan
 
PPTX
JavaScript: Implementations And Applications
Pragya Pai
 
PPTX
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Gil Irizarry
 
Learn Javascript Basics
Khushiar
 
Hsc IT Chap 3. Advanced javascript-1.pdf
AAFREEN SHAIKH
 
INTERNSHIP PPT - INFOLABZ.pptx
DevChaudhari15
 
216170316007.pptx
DevChaudhari15
 
Google Assistant Revolution
Rafael Casuso Romate
 
HNDIT1022 Week 08, 09 10 Theory web .pptx
IsuriUmayangana
 
Make Mobile Apps Quickly
Gil Irizarry
 
Android Jump Start
Haim Michael
 
Free and Open Source Software
Moinuddin Ahmed
 
Raja3Years
Raja Ravichandran
 
Done in 60 seconds - Creating Web 2.0 applications made easy
Roel Hartman
 
Techjoomla Infrastructure Extensions - Adding an Enterprise Layer to Joomla!
Parth Lawate
 
Taming the Legacy Beast: Turning wild old code into a sleak new thoroughbread.
Chris Laning
 
Introduction to JavaScript, functions, DOM
LikhithaBrunda
 
MAST Portal: drivers and recommendations
Alberto Conti
 
Joget Workflow v6 Training Slides - 8 - Designing your First Userview
Joget Workflow
 
Mychoice -classified site for buying, selling, rent etc
Nikhil Palyekar
 
Basic iOS Training with SWIFT - Part 4
Manoj Ellappan
 
JavaScript: Implementations And Applications
Pragya Pai
 
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Gil Irizarry
 
Ad

More from Mudasir Syed (20)

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

Recently uploaded (20)

PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Mathematics 5 - Time Measurement: Time Zone
menchreo
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
PPTX
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
Zoology (Animal Physiology) practical Manual
raviralanaresh2
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PPTX
PPT on the Development of Education in the Victorian England
Beena E S
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Mathematics 5 - Time Measurement: Time Zone
menchreo
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Dimensions of Societal Planning in Commonism
StefanMz
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Zoology (Animal Physiology) practical Manual
raviralanaresh2
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PPT on the Development of Education in the Victorian England
Beena E S
 

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