SlideShare a Scribd company logo
1 of 32
INTRO TO JAVASCRIPT
SESSION 12
Aptech Computer Education
Presented by Muhammad Ehtisham Siddiqui (BSCS)
1
Objectives
 Explain scripting
 Explain the JavaScript language
 Explain the client-side and server-side JavaScript
 List the variables and data types in JavaScript
 Describe the JavaScript methods to display
information
 Explain escape sequences and built in functions in
JavaScript
 Explain events and event handling
 Explain jQuery
 Describe how to use the jQuery Mobile
Presented by Muhammad Ehtisham Siddiqui (BSCS)
2
CASE
Presented by Muhammad Ehtisham Siddiqui
(BSCS)
3
CASE:
Consider an organization that provides a Web site that allows its customers to view
their products. The company has received frequent customer feedbacks to provide
the shopping facility online. Therefore, the company has decided to add the
shopping facility in their Web site by creating dynamic Web pages. These Web
pages will allow the user to shop for the products online. Here, the main task of the
developer is to validate the customer’s inputs while they shop online. For example,
details such as credit card number, email, and phone number entered by the
customer must be in a proper format. Further, the developer also needs to retrieve
the chosen products and their quantity to calculate the total cost.
SOLUTION
The developer can handle all these critical tasks by using a scripting language. A
scripting language refers to a set of instructions that provides some functionality
when the user interacts with a Web page.
SCRIPTING
Presented by Muhammad Ehtisham Siddiqui
(BSCS)
4
 displays the need for scripting
Scripting
Presented by Muhammad Ehtisham Siddiqui
(BSCS)
5
 Scripting refers to a series of commands that are interpreted and executed
sequentially and immediately on occurrence of an event.
 This event is an action generated by a user while interacting with a Web page.
 Examples of events include button clicks, selecting a product from a menu, and so
on.
 Scripting languages are often embedded in the HTML pages to change the behavior
of the Web pages according to the user’s requirements.
 There are two types of scripting languages. They are as follows:
Intro to JavaScript
Presented by Muhammad Ehtisham Siddiqui
(BSCS)
6
 JavaScript is a scripting language that allows you to build dynamic Web pages
by ensuring maximum user interactivity.
 JavaScript language is an object-based language, which means that it
provides objects for specifying functionalities.
 In real life, an object is a visible entity such as a car or a table. Every object
has some characteristics and is capable of performing certain actions.
 Similarly, in a scripting language, an object has a unique identity, state, and
behavior.
 The identity of the object distinguishes it from the other objects of the same
type. The state of the object refers to its characteristics, whereas the behavior
of the object consists of its possible actions.
 The object stores its identity and state in fields (also called variables) and
exposes its behavior through functions (actions).
Intro to JavaScript
Presented by Muhammad Ehtisham Siddiqui
(BSCS)
7
 Display the object
Client-side JavaScript
Presented by Muhammad Ehtisham Siddiqui
(BSCS)
8
 JavaScript is a scripting language, which can be executed on the client-side
and on the
server-side.
 A client-side JavaScript (CSJS) is executed by the browser on the user’s
workstation.
 A client-side script might contain instructions for the browser to handle
user interactivity.
 . Examples include displaying a welcome page with the username,
displaying date and time, validating that the required user details are filled,
and so on.
Server-side JavaScript
Presented by Muhammad Ehtisham Siddiqui
(BSCS)
9
 A server-side JavaScript (SSJS) is executed by the Web server when an HTML page
is requested by a user.
 The output of a server-side JavaScript is sent to the user and is displayed by the
browser.
 .In this case, a user might not be aware that a script was executed on the server to
produce the desirable output.
 Suppose, if the browser does not support the <video> element then the content
between the start tag and end tag is displayed on the browser.
 A server-side JavaScript can interact with the database, fetch the required
information specific to the user, and display it to the user. This means that server-
side scripting fulfills the goal of providing dynamic content in Web pages. Unlike
client-side JavaScript, HTML pages using server-side JavaScript are compiled into
bytecode files on the server. Compilation is a process of converting the code into
machine-independent code. This machine-independent code is known as the
bytecode, which is an executable file. The Web server runs this executable to
generate the desired output.
Server-Side JavaScript
Presented by Muhammad Ehtisham Siddiqui
(BSCS)
10
<Script> Tag
Presented by Muhammad Ehtisham Siddiqui
(BSCS)
11
 The <script> tag defines a script for an HTML page to make them interactive
 The browser that supports scripts interprets and executes the script specified under
the <script> tag when the page loads in the browser.
 You can directly insert a JavaScript code under the <script> tag. You can define
multiple <script> tags either in the <head> or in the <body> elements of an HTML
page.
 In HTML5, the type attribute specifying the scripting language is no longer required
as it is optional.
 There are two main purposes of the <script> tag, which are as follows:
 Identifies a given segment of script in the HTML page
 Loads an external script file
JavaScript Code
Presented by Muhammad Ehtisham Siddiqui
(BSCS)
12
 <!DOCTYPE html>
 <html>
 <head>
 <script>
 document.write(“Welcome to the Digital World”);
 </script>
 </head>
 <body>
 <h1>This is First JavaScript Code</h1>
 </body>
 </html>
JavaScript Code
Presented by Muhammad Ehtisham Siddiqui
(BSCS)
13
<!DOCTYPE html>
<html>
<body>
<h2>My First JavaScript</h2>
<button type="button"
onclick="document.getElementById('demo').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="demo"></p>
</body>
</html>
Variable
Presented by Muhammad Ehtisham Siddiqui
(BSCS)
14
 A variable refers to a symbolic name that holds a value, which keeps changing.
 For example, age of a student and salary of an employee can be treated as
variables.
 A real life example for variables includes the variables used in algebraic
expressions that store values.
 You can do variable initialization at the time of variablecreation or at a later point in
time when you need that variable.
Declaring Varibles
Presented by Muhammad Ehtisham Siddiqui (BSCS)
15
 The syntax demonstrates how to declare variables in
JavaScript.
 Syntax
<variableName> = <value>;
where, =: Is the assignment operator used to assign values.
 Code:
var studID;
var studName;
studID = 50;
StudName = “David Fernando”
Methods
Presented by Muhammad Ehtisham Siddiqui (BSCS)
16
 JavaScript allows you to display information using the methods
of the document object.
 The document object is a predefined object in JavaScript, which
represents the HTML page and allow managing the page
dynamically.
 Each object in JavaScript consists of methods, which fulfills a
specific task.
 There are two methods of the document object, which displays
any type of data in the browser. These methods are as follows:
 write(): Displays any type of data.
 writeln(): Displays any type of data and appends a new line
character.
 SYNTAX:
document.write(“<data>” + variables);
Functions
Presented by Muhammad Ehtisham Siddiqui (BSCS)
17
 A JavaScript function is a block of code designed to
perform a particular task.
 A JavaScript function is executed when "something"
invokes it (calls it).
 A JavaScript function is defined with
the function keyword, followed by a name, followed by
parentheses ().
 Syntax:
function name(parameter1, parameter2, parameter3) {
code to be executed
}
Functions Code
Presented by Muhammad Ehtisham Siddiqui (BSCS)
18
<!DOCTYPE html>
<html><head>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph
changed.";
}
</script>
</head>
<body>
<h1>A Web Page</h1>
<p id="demo">A Paragraph</p>
<button type="button" onclick="myFunction()">Try it</button>
</body>
</html>
Functions Code (Change CSS)
Presented by Muhammad Ehtisham Siddiqui (BSCS)
19
<!DOCTYPE html>
<html><head>
<script>
function ChangeCss(){
document.getElementById("JCss").style.backgroundColor="Red";
}
</script></head>
<body>
<h1>A Web Page</h1>
<p id="demo">This is Iran</p>
<p id="JCss">This is Pakistan</p>
<button id="btn" onClick="myFunction()">Check Function</button>
<button id="btn" onClick="ChangeCss()">Change Css</button>
</body>
</html>
Built-in Functions
Presented by Muhammad Ehtisham Siddiqui (BSCS)
20
Functions Description Example
alert() Displays a dialog box with some
information and OK button
alert(“Please fill all the fields
of the form”); Displays a
message box with the
instruction
confirm() Displays a dialog box with OK and
Cancel buttons. It verifies an action,
which a user wants to perform
confirm(“Are you sure you
want to close the page?”);
Displays a message box with
the question
parseInt() Converts a string value into a numeric
value
parseInt(“25 years”);
prompt() Displays a dialog box that accepts an
input value through a text box. It also
accepts the default value for the text box.
prompt(“Enter your name”,
“Name”); Displays the
message in the dialog box
and Name in the text box.
eval() Evaluates an expression and returns the
evaluated result
eval(“2+2”); Returns 4
Alert (Try Code)
Presented by Muhammad Ehtisham Siddiqui (BSCS)
21
<!DOCTYPE html>
<html>
<head><title>JS Alert</title>
<script>
function myFunction() {
alert("You have created alert box");
}
</script></head>
<body>
<h2>JavaScript Alert</h2>
<button onclick="myFunction()">Try it</button>
</body>
</html>
Prompt (Try Code)
Presented by Muhammad Ehtisham Siddiqui (BSCS)
22
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
var person = prompt("Please enter your name", "Harry Potter");
if (person != null) {
document.getElementById("demo").innerHTML =
"Hello " + person + "! How are you today?"; }}
</script>
</head>
<body>
<p>Click the button to demonstrate the prompt box.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
</body>
</html>
TASK
Presented by Muhammad Ehtisham Siddiqui (BSCS)
23
Take 2 input from user by prompt and display by
multiplying it.
Event Handling
Presented by Muhammad Ehtisham Siddiqui (BSCS)
24
 Event handling is a process of specifying actions to be performed
when an event occurs.
 This is done by using an event handler.
 An event handler is a scripting code or a function that defines the
actions to be performed when the event is triggered.
 When an event occurs, an event handler function that is associated
with the specific event is invoked.
 The information about this generated event is updated on the event
object.
 It specifies the event state, which includes information such as the
location of mouse cursor, element on which an event occurred, and
state of the keys in a keyboard.
Event Handling
Presented by Muhammad Ehtisham Siddiqui (BSCS)
25
Event Handling
Presented by Muhammad Ehtisham Siddiqui (BSCS)
26
Event Handling Life Cycle
Presented by Muhammad Ehtisham Siddiqui (BSCS)
27
The user
performs an
action to raise
an event.
The event
object is
updated to
determine the
event state.
The event is
fired.
The event
bubbling
occurs as the
event bubbles
through the
elements of
the hierarchy.
The event
handler is
invoked that
performs the
specified
actions.
Some events
Presented by Muhammad Ehtisham Siddiqui (BSCS)
28
Events Description
onmousedo
wn
Occurs when the mouse button is pressed
onmouseup Occurs when the mouse button is released
onclick Occurs when the mouse button is pressed and release
ondblclick Occurs when the mouse button is double-clicked
onmousemo
ve
Occurs when the mouse pointer is moved from one location to
other
onmouseove
r
Occurs when the mouse pointer is moved over the element
onmouseout Occurs when the mouse pointer is moved out of the element
Some events
Presented by Muhammad Ehtisham Siddiqui (BSCS)
29
Events Description
onmousedo
wn
Occurs when the mouse button is pressed
onmouseup Occurs when the mouse button is released
onclick Occurs when the mouse button is pressed and release
ondblclick Occurs when the mouse button is double-clicked
onmousemo
ve
Occurs when the mouse pointer is moved from one location to
other
onmouseove
r
Occurs when the mouse pointer is moved over the element
onmouseout Occurs when the mouse pointer is moved out of the element
External JavaScript
Presented by Muhammad Ehtisham Siddiqui (BSCS)
30
 Scripts can also be placed in external files:
<!DOCTYPE html>
<html>
<body>
<h2>External JavaScript</h2>
<p id="demo">A Paragraph.</p>
<button type="button"
onclick="myFunction()">Try
it</button>
<p>(myFunction is stored in an
external file called "myScript.js")</p>
<script src="myScript.js"></script>
</body></html>
HTML File
myScript.js
function myFunction() {
document.getElement
ById("demo").innerHTM
L = "Paragraph
changed.";
}
External JavaScript
Presented by Muhammad Ehtisham Siddiqui (BSCS)
31
 External scripts are practical when the same code is used in many different web
pages.
 JavaScript files have the file extension .js.
 To use an external script, put the name of the script file in the src (source) attribute of
a <script> tag.
 External JavaScript Advantages:
1. It separates HTML and code
2. It makes HTML and JavaScript easier to read and maintain
3. Cached JavaScript files can speed up page loads
 To add several script files to one page - use several script tags:
<script src="myScript1.js"></script>
<script src="myScript2.js"></script>
Questions?
Presented by Muhammad Ehtisham Siddiqui (BSCS)
32

More Related Content

Similar to Javascript session 1

Basic Java script handouts for students
Basic Java script handouts for students Basic Java script handouts for students
Basic Java script handouts for students shafiq sangi
 
Client side scripting using Javascript
Client side scripting using JavascriptClient side scripting using Javascript
Client side scripting using JavascriptBansari Shah
 
Java Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAXJava Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAXIMC Institute
 
HTML5 Up and Running
HTML5 Up and RunningHTML5 Up and Running
HTML5 Up and RunningCodemotion
 
PPT on javascript ajax and css and some points related to server
PPT on javascript ajax and css and some points related to serverPPT on javascript ajax and css and some points related to server
PPT on javascript ajax and css and some points related to servershivanichourasia01
 
Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applicationsdominion
 
Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Jonas Follesø
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPTGo4Guru
 
CHAPTER 3 JS (1).pptx
CHAPTER 3  JS (1).pptxCHAPTER 3  JS (1).pptx
CHAPTER 3 JS (1).pptxachutachut
 
Having Fun Building Web Applications (Day 1 Slides)
Having Fun Building Web Applications (Day 1 Slides)Having Fun Building Web Applications (Day 1 Slides)
Having Fun Building Web Applications (Day 1 Slides)Clarence Ngoh
 
01 Introduction - JavaScript Development
01 Introduction - JavaScript Development01 Introduction - JavaScript Development
01 Introduction - JavaScript DevelopmentTommy Vercety
 
Session vii(java scriptbasics)
Session vii(java scriptbasics)Session vii(java scriptbasics)
Session vii(java scriptbasics)Shrijan Tiwari
 
Front End Lecture 1.pptx
Front End Lecture 1.pptxFront End Lecture 1.pptx
Front End Lecture 1.pptxmalise2997
 

Similar to Javascript session 1 (20)

JavaScript
JavaScriptJavaScript
JavaScript
 
Basic Java script handouts for students
Basic Java script handouts for students Basic Java script handouts for students
Basic Java script handouts for students
 
Client side scripting using Javascript
Client side scripting using JavascriptClient side scripting using Javascript
Client side scripting using Javascript
 
Presentation
PresentationPresentation
Presentation
 
Lecture-15.pptx
Lecture-15.pptxLecture-15.pptx
Lecture-15.pptx
 
Java Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAXJava Web Programming [8/9] : JSF and AJAX
Java Web Programming [8/9] : JSF and AJAX
 
web devs ppt.ppsx
web devs ppt.ppsxweb devs ppt.ppsx
web devs ppt.ppsx
 
HTML5 Up and Running
HTML5 Up and RunningHTML5 Up and Running
HTML5 Up and Running
 
PPT on javascript ajax and css and some points related to server
PPT on javascript ajax and css and some points related to serverPPT on javascript ajax and css and some points related to server
PPT on javascript ajax and css and some points related to server
 
Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applications
 
Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
 
Overview of PHP and MYSQL
Overview of PHP and MYSQLOverview of PHP and MYSQL
Overview of PHP and MYSQL
 
CHAPTER 3 JS (1).pptx
CHAPTER 3  JS (1).pptxCHAPTER 3  JS (1).pptx
CHAPTER 3 JS (1).pptx
 
Java script
Java scriptJava script
Java script
 
Having Fun Building Web Applications (Day 1 Slides)
Having Fun Building Web Applications (Day 1 Slides)Having Fun Building Web Applications (Day 1 Slides)
Having Fun Building Web Applications (Day 1 Slides)
 
01 Introduction - JavaScript Development
01 Introduction - JavaScript Development01 Introduction - JavaScript Development
01 Introduction - JavaScript Development
 
Java Script
Java ScriptJava Script
Java Script
 
Session vii(java scriptbasics)
Session vii(java scriptbasics)Session vii(java scriptbasics)
Session vii(java scriptbasics)
 
Front End Lecture 1.pptx
Front End Lecture 1.pptxFront End Lecture 1.pptx
Front End Lecture 1.pptx
 

More from Muhammad Ehtisham Siddiqui

J Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham SiddiquiJ Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham SiddiquiMuhammad Ehtisham Siddiqui
 
Buiding Next Generation Websites Session 8 by Muhammad Ehtisham Siddiqui
Buiding Next Generation Websites Session 8 by Muhammad Ehtisham SiddiquiBuiding Next Generation Websites Session 8 by Muhammad Ehtisham Siddiqui
Buiding Next Generation Websites Session 8 by Muhammad Ehtisham SiddiquiMuhammad Ehtisham Siddiqui
 
Building Next Generation Websites Session 7 by Muhammad Ehtisham Siddiqui
Building Next Generation  Websites Session 7 by Muhammad Ehtisham SiddiquiBuilding Next Generation  Websites Session 7 by Muhammad Ehtisham Siddiqui
Building Next Generation Websites Session 7 by Muhammad Ehtisham SiddiquiMuhammad Ehtisham Siddiqui
 
Building Next Generation Websites Session 6 by Muhammad Ehtisham Siddiqui
Building Next Generation Websites Session 6 by Muhammad Ehtisham SiddiquiBuilding Next Generation Websites Session 6 by Muhammad Ehtisham Siddiqui
Building Next Generation Websites Session 6 by Muhammad Ehtisham SiddiquiMuhammad Ehtisham Siddiqui
 
Building Next Generation Websites by Muhammad Ehtisham Siddiqui
Building Next Generation Websites by Muhammad Ehtisham SiddiquiBuilding Next Generation Websites by Muhammad Ehtisham Siddiqui
Building Next Generation Websites by Muhammad Ehtisham SiddiquiMuhammad Ehtisham Siddiqui
 

More from Muhammad Ehtisham Siddiqui (20)

C programming Tutorial Session 4
C programming Tutorial Session 4C programming Tutorial Session 4
C programming Tutorial Session 4
 
C programming Tutorial Session 4
C programming Tutorial Session 4C programming Tutorial Session 4
C programming Tutorial Session 4
 
C programming Tutorial Session 3
C programming Tutorial Session 3C programming Tutorial Session 3
C programming Tutorial Session 3
 
C programming Tutorial Session 2
C programming Tutorial Session 2C programming Tutorial Session 2
C programming Tutorial Session 2
 
C programming Tutorial Session 1
C programming Tutorial Session 1C programming Tutorial Session 1
C programming Tutorial Session 1
 
HTML5 Web storage
HTML5 Web storageHTML5 Web storage
HTML5 Web storage
 
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham SiddiquiJ Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
 
JavaScript Session 2
JavaScript Session 2JavaScript Session 2
JavaScript Session 2
 
JavaScript Session 3
JavaScript Session 3JavaScript Session 3
JavaScript Session 3
 
Html audio video
Html audio videoHtml audio video
Html audio video
 
Html 5 geolocation api
Html 5 geolocation api Html 5 geolocation api
Html 5 geolocation api
 
Buiding Next Generation Websites Session 8 by Muhammad Ehtisham Siddiqui
Buiding Next Generation Websites Session 8 by Muhammad Ehtisham SiddiquiBuiding Next Generation Websites Session 8 by Muhammad Ehtisham Siddiqui
Buiding Next Generation Websites Session 8 by Muhammad Ehtisham Siddiqui
 
Building Next Generation Websites Session 7 by Muhammad Ehtisham Siddiqui
Building Next Generation  Websites Session 7 by Muhammad Ehtisham SiddiquiBuilding Next Generation  Websites Session 7 by Muhammad Ehtisham Siddiqui
Building Next Generation Websites Session 7 by Muhammad Ehtisham Siddiqui
 
Building Next Generation Websites Session 6 by Muhammad Ehtisham Siddiqui
Building Next Generation Websites Session 6 by Muhammad Ehtisham SiddiquiBuilding Next Generation Websites Session 6 by Muhammad Ehtisham Siddiqui
Building Next Generation Websites Session 6 by Muhammad Ehtisham Siddiqui
 
Building Next Generation Websites by Muhammad Ehtisham Siddiqui
Building Next Generation Websites by Muhammad Ehtisham SiddiquiBuilding Next Generation Websites by Muhammad Ehtisham Siddiqui
Building Next Generation Websites by Muhammad Ehtisham Siddiqui
 
Building Next Generation Websites Session6
Building Next Generation Websites Session6Building Next Generation Websites Session6
Building Next Generation Websites Session6
 
Building Next Generation Websites Session5
Building Next Generation Websites Session5Building Next Generation Websites Session5
Building Next Generation Websites Session5
 
Building Next Generation Websites Session4
Building Next Generation Websites Session4Building Next Generation Websites Session4
Building Next Generation Websites Session4
 
Session4
Session4Session4
Session4
 
Office session14
Office session14Office session14
Office session14
 

Recently uploaded

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 

Recently uploaded (20)

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

Javascript session 1

  • 1. INTRO TO JAVASCRIPT SESSION 12 Aptech Computer Education Presented by Muhammad Ehtisham Siddiqui (BSCS) 1
  • 2. Objectives  Explain scripting  Explain the JavaScript language  Explain the client-side and server-side JavaScript  List the variables and data types in JavaScript  Describe the JavaScript methods to display information  Explain escape sequences and built in functions in JavaScript  Explain events and event handling  Explain jQuery  Describe how to use the jQuery Mobile Presented by Muhammad Ehtisham Siddiqui (BSCS) 2
  • 3. CASE Presented by Muhammad Ehtisham Siddiqui (BSCS) 3 CASE: Consider an organization that provides a Web site that allows its customers to view their products. The company has received frequent customer feedbacks to provide the shopping facility online. Therefore, the company has decided to add the shopping facility in their Web site by creating dynamic Web pages. These Web pages will allow the user to shop for the products online. Here, the main task of the developer is to validate the customer’s inputs while they shop online. For example, details such as credit card number, email, and phone number entered by the customer must be in a proper format. Further, the developer also needs to retrieve the chosen products and their quantity to calculate the total cost. SOLUTION The developer can handle all these critical tasks by using a scripting language. A scripting language refers to a set of instructions that provides some functionality when the user interacts with a Web page.
  • 4. SCRIPTING Presented by Muhammad Ehtisham Siddiqui (BSCS) 4  displays the need for scripting
  • 5. Scripting Presented by Muhammad Ehtisham Siddiqui (BSCS) 5  Scripting refers to a series of commands that are interpreted and executed sequentially and immediately on occurrence of an event.  This event is an action generated by a user while interacting with a Web page.  Examples of events include button clicks, selecting a product from a menu, and so on.  Scripting languages are often embedded in the HTML pages to change the behavior of the Web pages according to the user’s requirements.  There are two types of scripting languages. They are as follows:
  • 6. Intro to JavaScript Presented by Muhammad Ehtisham Siddiqui (BSCS) 6  JavaScript is a scripting language that allows you to build dynamic Web pages by ensuring maximum user interactivity.  JavaScript language is an object-based language, which means that it provides objects for specifying functionalities.  In real life, an object is a visible entity such as a car or a table. Every object has some characteristics and is capable of performing certain actions.  Similarly, in a scripting language, an object has a unique identity, state, and behavior.  The identity of the object distinguishes it from the other objects of the same type. The state of the object refers to its characteristics, whereas the behavior of the object consists of its possible actions.  The object stores its identity and state in fields (also called variables) and exposes its behavior through functions (actions).
  • 7. Intro to JavaScript Presented by Muhammad Ehtisham Siddiqui (BSCS) 7  Display the object
  • 8. Client-side JavaScript Presented by Muhammad Ehtisham Siddiqui (BSCS) 8  JavaScript is a scripting language, which can be executed on the client-side and on the server-side.  A client-side JavaScript (CSJS) is executed by the browser on the user’s workstation.  A client-side script might contain instructions for the browser to handle user interactivity.  . Examples include displaying a welcome page with the username, displaying date and time, validating that the required user details are filled, and so on.
  • 9. Server-side JavaScript Presented by Muhammad Ehtisham Siddiqui (BSCS) 9  A server-side JavaScript (SSJS) is executed by the Web server when an HTML page is requested by a user.  The output of a server-side JavaScript is sent to the user and is displayed by the browser.  .In this case, a user might not be aware that a script was executed on the server to produce the desirable output.  Suppose, if the browser does not support the <video> element then the content between the start tag and end tag is displayed on the browser.  A server-side JavaScript can interact with the database, fetch the required information specific to the user, and display it to the user. This means that server- side scripting fulfills the goal of providing dynamic content in Web pages. Unlike client-side JavaScript, HTML pages using server-side JavaScript are compiled into bytecode files on the server. Compilation is a process of converting the code into machine-independent code. This machine-independent code is known as the bytecode, which is an executable file. The Web server runs this executable to generate the desired output.
  • 10. Server-Side JavaScript Presented by Muhammad Ehtisham Siddiqui (BSCS) 10
  • 11. <Script> Tag Presented by Muhammad Ehtisham Siddiqui (BSCS) 11  The <script> tag defines a script for an HTML page to make them interactive  The browser that supports scripts interprets and executes the script specified under the <script> tag when the page loads in the browser.  You can directly insert a JavaScript code under the <script> tag. You can define multiple <script> tags either in the <head> or in the <body> elements of an HTML page.  In HTML5, the type attribute specifying the scripting language is no longer required as it is optional.  There are two main purposes of the <script> tag, which are as follows:  Identifies a given segment of script in the HTML page  Loads an external script file
  • 12. JavaScript Code Presented by Muhammad Ehtisham Siddiqui (BSCS) 12  <!DOCTYPE html>  <html>  <head>  <script>  document.write(“Welcome to the Digital World”);  </script>  </head>  <body>  <h1>This is First JavaScript Code</h1>  </body>  </html>
  • 13. JavaScript Code Presented by Muhammad Ehtisham Siddiqui (BSCS) 13 <!DOCTYPE html> <html> <body> <h2>My First JavaScript</h2> <button type="button" onclick="document.getElementById('demo').innerHTML = Date()"> Click me to display Date and Time.</button> <p id="demo"></p> </body> </html>
  • 14. Variable Presented by Muhammad Ehtisham Siddiqui (BSCS) 14  A variable refers to a symbolic name that holds a value, which keeps changing.  For example, age of a student and salary of an employee can be treated as variables.  A real life example for variables includes the variables used in algebraic expressions that store values.  You can do variable initialization at the time of variablecreation or at a later point in time when you need that variable.
  • 15. Declaring Varibles Presented by Muhammad Ehtisham Siddiqui (BSCS) 15  The syntax demonstrates how to declare variables in JavaScript.  Syntax <variableName> = <value>; where, =: Is the assignment operator used to assign values.  Code: var studID; var studName; studID = 50; StudName = “David Fernando”
  • 16. Methods Presented by Muhammad Ehtisham Siddiqui (BSCS) 16  JavaScript allows you to display information using the methods of the document object.  The document object is a predefined object in JavaScript, which represents the HTML page and allow managing the page dynamically.  Each object in JavaScript consists of methods, which fulfills a specific task.  There are two methods of the document object, which displays any type of data in the browser. These methods are as follows:  write(): Displays any type of data.  writeln(): Displays any type of data and appends a new line character.  SYNTAX: document.write(“<data>” + variables);
  • 17. Functions Presented by Muhammad Ehtisham Siddiqui (BSCS) 17  A JavaScript function is a block of code designed to perform a particular task.  A JavaScript function is executed when "something" invokes it (calls it).  A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses ().  Syntax: function name(parameter1, parameter2, parameter3) { code to be executed }
  • 18. Functions Code Presented by Muhammad Ehtisham Siddiqui (BSCS) 18 <!DOCTYPE html> <html><head> <script> function myFunction() { document.getElementById("demo").innerHTML = "Paragraph changed."; } </script> </head> <body> <h1>A Web Page</h1> <p id="demo">A Paragraph</p> <button type="button" onclick="myFunction()">Try it</button> </body> </html>
  • 19. Functions Code (Change CSS) Presented by Muhammad Ehtisham Siddiqui (BSCS) 19 <!DOCTYPE html> <html><head> <script> function ChangeCss(){ document.getElementById("JCss").style.backgroundColor="Red"; } </script></head> <body> <h1>A Web Page</h1> <p id="demo">This is Iran</p> <p id="JCss">This is Pakistan</p> <button id="btn" onClick="myFunction()">Check Function</button> <button id="btn" onClick="ChangeCss()">Change Css</button> </body> </html>
  • 20. Built-in Functions Presented by Muhammad Ehtisham Siddiqui (BSCS) 20 Functions Description Example alert() Displays a dialog box with some information and OK button alert(“Please fill all the fields of the form”); Displays a message box with the instruction confirm() Displays a dialog box with OK and Cancel buttons. It verifies an action, which a user wants to perform confirm(“Are you sure you want to close the page?”); Displays a message box with the question parseInt() Converts a string value into a numeric value parseInt(“25 years”); prompt() Displays a dialog box that accepts an input value through a text box. It also accepts the default value for the text box. prompt(“Enter your name”, “Name”); Displays the message in the dialog box and Name in the text box. eval() Evaluates an expression and returns the evaluated result eval(“2+2”); Returns 4
  • 21. Alert (Try Code) Presented by Muhammad Ehtisham Siddiqui (BSCS) 21 <!DOCTYPE html> <html> <head><title>JS Alert</title> <script> function myFunction() { alert("You have created alert box"); } </script></head> <body> <h2>JavaScript Alert</h2> <button onclick="myFunction()">Try it</button> </body> </html>
  • 22. Prompt (Try Code) Presented by Muhammad Ehtisham Siddiqui (BSCS) 22 <!DOCTYPE html> <html> <head> <script> function myFunction() { var person = prompt("Please enter your name", "Harry Potter"); if (person != null) { document.getElementById("demo").innerHTML = "Hello " + person + "! How are you today?"; }} </script> </head> <body> <p>Click the button to demonstrate the prompt box.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> </body> </html>
  • 23. TASK Presented by Muhammad Ehtisham Siddiqui (BSCS) 23 Take 2 input from user by prompt and display by multiplying it.
  • 24. Event Handling Presented by Muhammad Ehtisham Siddiqui (BSCS) 24  Event handling is a process of specifying actions to be performed when an event occurs.  This is done by using an event handler.  An event handler is a scripting code or a function that defines the actions to be performed when the event is triggered.  When an event occurs, an event handler function that is associated with the specific event is invoked.  The information about this generated event is updated on the event object.  It specifies the event state, which includes information such as the location of mouse cursor, element on which an event occurred, and state of the keys in a keyboard.
  • 25. Event Handling Presented by Muhammad Ehtisham Siddiqui (BSCS) 25
  • 26. Event Handling Presented by Muhammad Ehtisham Siddiqui (BSCS) 26
  • 27. Event Handling Life Cycle Presented by Muhammad Ehtisham Siddiqui (BSCS) 27 The user performs an action to raise an event. The event object is updated to determine the event state. The event is fired. The event bubbling occurs as the event bubbles through the elements of the hierarchy. The event handler is invoked that performs the specified actions.
  • 28. Some events Presented by Muhammad Ehtisham Siddiqui (BSCS) 28 Events Description onmousedo wn Occurs when the mouse button is pressed onmouseup Occurs when the mouse button is released onclick Occurs when the mouse button is pressed and release ondblclick Occurs when the mouse button is double-clicked onmousemo ve Occurs when the mouse pointer is moved from one location to other onmouseove r Occurs when the mouse pointer is moved over the element onmouseout Occurs when the mouse pointer is moved out of the element
  • 29. Some events Presented by Muhammad Ehtisham Siddiqui (BSCS) 29 Events Description onmousedo wn Occurs when the mouse button is pressed onmouseup Occurs when the mouse button is released onclick Occurs when the mouse button is pressed and release ondblclick Occurs when the mouse button is double-clicked onmousemo ve Occurs when the mouse pointer is moved from one location to other onmouseove r Occurs when the mouse pointer is moved over the element onmouseout Occurs when the mouse pointer is moved out of the element
  • 30. External JavaScript Presented by Muhammad Ehtisham Siddiqui (BSCS) 30  Scripts can also be placed in external files: <!DOCTYPE html> <html> <body> <h2>External JavaScript</h2> <p id="demo">A Paragraph.</p> <button type="button" onclick="myFunction()">Try it</button> <p>(myFunction is stored in an external file called "myScript.js")</p> <script src="myScript.js"></script> </body></html> HTML File myScript.js function myFunction() { document.getElement ById("demo").innerHTM L = "Paragraph changed."; }
  • 31. External JavaScript Presented by Muhammad Ehtisham Siddiqui (BSCS) 31  External scripts are practical when the same code is used in many different web pages.  JavaScript files have the file extension .js.  To use an external script, put the name of the script file in the src (source) attribute of a <script> tag.  External JavaScript Advantages: 1. It separates HTML and code 2. It makes HTML and JavaScript easier to read and maintain 3. Cached JavaScript files can speed up page loads  To add several script files to one page - use several script tags: <script src="myScript1.js"></script> <script src="myScript2.js"></script>
  • 32. Questions? Presented by Muhammad Ehtisham Siddiqui (BSCS) 32

Editor's Notes

  1. Presentation slide for courses, classes, lectures et al.
  2. Beginning course details and/or books/materials needed for a class/project.
  3. Beginning course details and/or books/materials needed for a class/project.
  4. Beginning course details and/or books/materials needed for a class/project.
  5. Beginning course details and/or books/materials needed for a class/project.
  6. Beginning course details and/or books/materials needed for a class/project.
  7. Beginning course details and/or books/materials needed for a class/project.
  8. Beginning course details and/or books/materials needed for a class/project.
  9. Beginning course details and/or books/materials needed for a class/project.
  10. Beginning course details and/or books/materials needed for a class/project.
  11. Beginning course details and/or books/materials needed for a class/project.
  12. Beginning course details and/or books/materials needed for a class/project.
  13. Beginning course details and/or books/materials needed for a class/project.
  14. Beginning course details and/or books/materials needed for a class/project.
  15. Example graph/chart.