SlideShare una empresa de Scribd logo
1 de 78
Descargar para leer sin conexión
DR ATIF SHAHZAD
Fundamentals of
Computer Systems
IE-321
LECTURE #17
RECAP
Logic
Logical variables
Conditional, Negation, Contrapositive,Biconditional
AND, OR,NOT,XOR
Logic gates
TruthTables
BooleanAlgebra
Examples
Q&A
MicrosoftVisio
Microsoft Project
Spreadsheet Concepts:
Using Microsoft Excel
Creating Charts in Microsoft Excel
Debugging Concepts Using Microsoft Excel
Presentation Concepts Using Microsoft PowerPoint
Image Concepts
Memory
Memory Cell
CPU
Register
Program Counter
Fetch-Execute Cycle
Q&A
File Management
Word Processing Basics Using MicrosoftWord
MicrosoftWord Layout and Graphics Features
Making and using compressed Files
WinZip, 7Zip
Notepad++
Wordpad
Adobe acrobat
Sumatra PDF
MathType
Database
Flat & Relational
Database
DBMS
Tables & Fields
Creating Tables in
Access
Design view and Data
Sheet View
Primary Key &
Foreign key
Relationships & ER
Diagram
Queries &Simple SQL
Cyber Security
Security Problems
Interception
Spoofing
Falsification
Repudiation
Security Technologies
Encryption
MAC
Data Model
Algorithm
Ingredients
Variables
Constructs
Pseudocode
Flowchart
Symbols
Flowcharting
examples
Q&A
9/27/2018 3
Dr.AtifShahzad
TODAY
Fundamentals of
Computer Systems
IE321
Javascript
9/27/2018
Dr.AtifShahzad
5
TheWeb Structure
9/27/2018
Dr.AtifShahzad
6
HTML:
Structure
CSS:
Presentation
JavaScript:
Behavior
HTML
• provides a page with structure and
CSS
• provides a page with appearance,
JavaScript
• provides a page with behavior.
Javascript
JavaScript
provides the ability
to add interactivity
to a website
help enrich the
user experience.
Javascript
JavaScript doesn’t need to be run through any
form of compiler that interprets our human-
readable code into something the browser can
understand.
The browser effectively reads the code and
interprets it on the fly.
Javascript
JavaScript
9/27/2018
Dr.AtifShahzad
10
JavaScript on the web
lives inside the HTML
document.
In HTML, JavaScript
code must be inserted
between <script> and
</script> tags:
<script>
...
</script>
JavaScript
9/27/2018
Dr.AtifShahzad
11
JS can be placed in the HTML page's
<body> section
<head> section.
JavaScript
9/27/2018
Dr.AtifShahzad
12
Adding Javascript to a Page
Like CSS,
you can embed a script right in a document or
keep it in an external file and link it to the page.
Embedded
Script
External
scripts
Adding Javascript to a Page
• To embed a script on a page, just add the code
as thecontent of a script element:
• <script>
• … JavaScript code goes here
• </script>
Embedded
Script
• The other method uses the src attribute to
point to a script file (with a .js suffix) by its
URL. In this case, the script element has no
content.
• <script src="my_script.js"></script>
External
scripts
Adding Javascript to a Page
<html>
<head> </head>
<body>
<script>
document.write("<h1>HelloWorld!</h1>");
</script>
</body>
</html>
The placement depends on when it should be executed.
Javascript can be placed for scripts
either in the head of the document or at the very end of the body.
Script Placement
• The best place to reference JavaScript files is right before the closing</bo
dy> tag so that the JavaScript file is loaded after all of the HTML has been
parsed.
• Putting it in header blocks the rendering of the page unless the whole file
is downloaded and executed, so moving the script to the bottom
improves the perceived performance.
• However, at times, JavaScript is needed to help render HTML and
determine it’s behavior, thus may be referenced within a document’s head
The placement depends on when it should be executed.
Javascript can be placed for scripts
either in the head of the document or at the very end of the body.
Script Placement
JS in head
<html>
<head>
<script>
</script>
</head>
<body>
</body>
</html>
JS in body
<html>
<head> </head>
<body>
<script>
</script>
</body>
</html>
Adding Javascript to a Page
<html>
<head>
<title></title>
<script type="text/javascript">
alert("This is an alert box!");
</script>
</head>
<body>
</body>
</html>
External JavaScript
Scripts can also be placed in external files.
External scripts are useful and practical when the same
code is used in a number of different web pages.
JavaScript files have the file extension.js
External JavaScript
<html>
<head>
<title> </title>
<script src=“IE321.js"></script>
</head>
<body>
</body>
</html> alert("This is an alert box!");
IE321.js
Statements Comments Variables Data types
Arrays
Comparison
Operators
If/else
Statements
Loops
Functions
Variable
Scope
Javascript Basics
A statement is a command that tells the
browser what to do.
A script is made up of a series of statements.
For example,alert("Thankyou.");is a statement.
The semicolon at the end indicates the end of the statement.
Statement
Single-line comments,
use two slash characters (//) at the beginning of the
line.
// This is a single-line comment.
Multiple-line comments
use the same syntax that you’ve seen in CSS.
Everything within the /* */ characters is ignored by
the browser.
Comments
/* This is a multi-line comment.
Anything between these sets of characters will be
completely ignored when the script is executed.
This form of comment needs to be closed. */
alert()
Alerts the user with some Message
Used for OUTPUT
9/27/2018
Dr.AtifShahzad
24
alert("Thanks for visiting");
document.write()
document.write("Another day");
Used for OUTPUT
9/27/2018
Dr.AtifShahzad
25
document.write("Thanks for visiting");
<html>
<head> </head>
<body>
<script>
document.write("HelloWorld!");
</script>
</body>
</html>
document.write()
9/27/2018
Dr.AtifShahzad
26
The document.write() function writes a
string into HTML document.
This function can be used to write text,
HTML, or both.
prompt()
The prompt() method takes two parameters.
The first is the label, which you want to display in the text
box.
The second is a default string to display in the text box
(optional).
9/27/2018
Dr.AtifShahzad
27
A prompt box is often used
to have the user 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 the input value.
If the user clicks OK, the
box returns the input value. If
the user clicks Cancel, the box
returns null.
var user = prompt("Please enter your name");
alert(user);
Used for
INPUT
A variable is like an information container.
You give it a name and then assign it a value, which can be a
number, text string, an element in the DOM, or a function.
The following declaration creates a variable with the name
“foo” and assigns it the value 5:
var foo = 5;
Variables
Undefined
The simplest of these data types is “undefined.” If we
declare a variable by giving it a name but no value, that
variable contains a value of “undefined.”
var foo;
alert(foo); // This will open a dialog containing "undefined".
Null
Assigning a variable of “null” (again, case-sensitive) simply
says,“Define this variable, but give it no inherent value.”
var foo = null;
alert(foo); // This will open a dialog containing "null".
Data types
Numbers
You can assign variables numeric values.
var foo = 5;
alert(foo); // This will open a dialog
containing "5".
The word “foo” now means the exact same thing as
the number five. Because JavaScript is “loosely
typed,” we don’t have to tell our script to treat the
variable foo as the number five.
Data types
Numbers
We can use classic mathematical notation: +,-,
*, and / for plus, minus, multiply, and divide,
respectively.
In this example, we use the plus sign (+) to add
foo to itself (foo + foo).
var foo = 5;
alert(foo + foo); // This will alert "10".
Data types
Strings
a line of text.
Enclosing characters in a set of single or double quotes
indicates that it’s a string.
var foo = "five";
alert( foo ); // This will alert "five"
The variable foo is now treated exactly the same as the word
“five”.
Data types
Strings
When the plus sign is used with strings, it sticks the strings
together (called concatenation) into one long string, as shown
in this example.
var foo = "bye"
alert (foo + foo); // This will alert "byebye“
var foo = "5";
alert( foo + foo ); // This will alert "55“
var foo = "five";
var bar = 5;
alert( foo + bar ); // This will alert "five5"
Data types
Strings
var mystring1 = "I am learning ";
var mystring2 = "JavaScript in IE321.";
document.write(mystring1 + mystring2);
Data types
Boolean
assign a variable a true or false value.
Boolean values use the true and false keywords
built into JavaScript, so quotation marks are
NOT necessary.
var foo = true; // The variable "foo" is now true
Data types
Arithmetic Operators
9/27/2018
Dr.AtifShahzad
36
Assignment Operators
9/27/2018
Dr.AtifShahzad
37
Increment/decrement Operators
Increment ++
• The increment operator increments the numeric value of its
operand by one. If placed before the operand, it returns the
incremented value. If placed after the operand, it returns the
original value and then increments the operand.
Decrement --
• The decrement operator decrements the numeric value of its
operand by one. If placed before the operand, it returns the
decremented value. If placed after the operand, it returns the
original value and then decrements the operand.
9/27/2018
Dr.AtifShahzad
38
Increment/decrement Operators
9/27/2018
Dr.AtifShahzad
39
A group of multiple values (called members) that
can be assigned to a single variable.
It is a way to store a list of items, or values.
The values in an array are said to be
indexed,
meaning you can refer to them by number according to the
order in which they appear in the list.The first member is
given the index number 0, the second is 1, and so on.
Arrays
For example,values in the array foo can be
accessed by referencing their index
number:
var foo = [5, "five", "5"];
alert( foo[0] ); // Alerts "5"
alert( foo[1] ); // Alerts "five"
alert( foo[2] ); // Also alerts "5"
Arrays
To compare two values,
JavaScript evaluates the statement and gives us
back a Boolean value depending on whether the
statement is true or false.
• == Is equal to
!= Is not equal to
• === Is identical to (equal to and of the same data type)
!== Is not identical to
> Is greater than
>= Is greater than or equal to
< Is less than
<= Is less than or equal to
Comparison Operators
alert( 5 == 5 ); // This will alert "true"
alert( 5 != 6 ); // This will alert "true"
alert( 5 < 1 ); // This will alert "false"
Comparison Operators
If/else statements are how we get
JavaScript to ask itself a true/false
question.
structure of a conditional statement:
if( true ) {
// Do something.
}
If/else statements
var foo = [5, "five", "5"];
if( foo[1] === "five" ) {
alert("This is the word five, written in plain English.");}
In this case, the alert would fire because the foo variable with an
index of 1 (the second in the list) is identical to “five”.
var test = "testing";
if( test == "testing" ) {
alert( "You haven't changed anything." );
} else {
alert( "You've changed something!" );
}
If/else statements
switch (expression) {
case n1:
statements
break;
case n2:
statements
break;
default:
statements
}
Switch Statement
when you need to
test for multiple
conditions
var day = 2;
switch (day) {
case 1:
document.write("Monday");
break;
case 2:
document.write("Tuesday");
break;
case 3:
document.write("Wednesday");
break;
default:
document.write("Another day");
}
// Outputs "Tuesday"
Switch Statement
There are cases in which we’ll want to go
through every item in an array and do
something with it,
several ways to write a loop, but the for
method is one of the most popular.
Loops
basic structure:
for( initialize the variable; test the condition; alter the value; )
{
// do something
}
Here is an example of a for loop in action.
for( var i = 0; i <= 2; i++ ) {
alert( i ); //This loop will trigger three alerts, reading "0", "1“,
and "2" respectively.
}
for Loops
check each item in an array” example.
var items = ["foo", "bar", "baz"];// First we create an array.
for( var i = 0; i <= items.length; i++ ) {
alert( items[i] ); //This will alert each item in the array.
}
For Loop--Exp
items.length
•Instead of using a number to limit the number of times the loop runs, we’re using a property built right into
JavaScript to determine the “length” of our array, which is the number of items it contains.
.length
items[i]
•We can use i variable inside of the loop to reference each index of the array.
basic structure:
while (condition) {
code block
}
while Loop
The while loop repeats through
a block of code, as long as a
specified condition is true.
Example:
var i=0;
while (i<=10) {
document.write(i + "<br />");
i++;
}
while Loop- Exp
A function is a bit of code that doesn’t run until it
is referenced or called.
alert() is a function built into our browser.
Functions
“out-of-the-box” (native JavaScript
functions)
(custom functions).
Native functions
Types of Functions
Native JavaScript
functions)
custom
functions
Types of Functions
hundreds of predefined functions built
into JavaScript, including:
alert(), confirm(), and prompt()
» These functions trigger browser-level dialog boxes.
Date() : Returns the current date and time.
parseInt("123"):This function will, among other things, take a
string data type containing numbers and turn it into a number
data type.The string is passed to the function as an argument.
SetTimeout(functionName, 5000):Will execute a function after
a delay.The function is specified in the first argument, and the
delay is specified in milliseconds in the second (in the example,
5000 milliseconds equals 5 seconds).
Native functions
To create a custom function, we type the
function keyword followed by a name for
the function, followed by opening and closing parentheses, followed
by opening and closing curly brackets.
function name() {
// Our function code goes here.
}
Custom
functions
There are times when you’ll want a variable
that you’ve defined within a function to be
available anywhere throughout your script.
Other times, you may want to restrict it and
make it available only to the function it lives
in.
This notion of the availability of the variable is
known as its scope.
Variable Scope
A variable that can be used by any of the
scripts on your page is globally scoped.
A variable that’s available only within its
parent function is locally scoped.
JavaScript variables use functions to manage
their scope. If a variable is defined outside of
a function, it will be globally scoped and
available to all scripts.
Variable Scope
When you define a variable within a function and you want
it to be used only by that function, you can flag it as locally
scoped by preceding the variable name with the var
keyword.
var foo = "value";
To expose a variable within a function to
the global scope, we omit the var keyword
and simply define the variable:
foo = "value";
Local vs Global variable
A variable declared outside a
function, becomes GLOBAL.
var carName = "Volvo";
// code here can use carName function
myFunction() {
// code here can use carName
}
Local vs Global variable
• <!DOCTYPE html>
• <html>
• <body>
• <p onclick="myFunction(),myFunction1();"
>Th e local variable carName cannot be ac
cessed from code outside the function:</p
>
• <p id="demo"></p>
• <script src="function.js"></script>
• </body>
• </html>
• function myFunction() {
• var carName = "Volvo";
• }
• function myFunction1()
• {
• document.getElementById("demo").inner
HTML ="The type of carName is " + typeof
carName;
• }
Local vs Global Variables
The return statement stops the execution
of a function and returns a value from that
function.
Return Statement
function addNumbers(a,b) {
return a + b;
}
Any reference you make to that function gives you the
result of the function.
alert( addNumbers(2,5) ); //Alerts "7“
Return Statement
What will be the output of the following
function
function bar() {
return 3;
alert(“displays alert.");
}
var x = bar ();
alert(x)
Return Statement
9/27/2018
Dr.AtifShahzad
67
NEVER hesitate to
contact should you
have any question
Dr.Atif Shahzad
<button id="btn" onclick="googleRedirect()">Redirect to Google!</button>
Browser Object Model
JavaScript gives you access to and the ability to manipulate the
parts of the browser window itself.
For example, we can make the browser to redirect to some URL on the click of a button.
You then call this function from the < body > element’ s onclick event, like so:
Then we can use this function to indicate where this browser should be redirected on the
click of a button.
To do this, first you need to add a function in a javascript file that is going to be
triggered when the button is clicked,
function googleRedirect()
{
window.location.assign("http://www.w
3schools.com");
}
Window Properties/ Methods
In JavaScript, the browser is known
as the window object. The window object has a number of
properties and methods that we can use to
interact with it.
Windows Events
For example, the onload
event handler triggers a
script when the document
loads.
Similarly onclick and
onmouseover handlers
trigger a script when the
user clicks or mouses over
an element, respectively.
An event is an action that can be detected with
JavaScript, such as when the document loads or
when the user clicks on an element or just
moves her mouse over it.
In scripts, an event is identified by an event
handler.
Events Handlers
• There are three ways we can apply event handlers within a webpage.
Applying Event Handlers
• <body onclick="myFunction();"> /* myFunction
will now run when the user clicks anything within
'body' */As an HTML
attribute
• <script>
• window.onclick = myFunction; /* myFunction will
run when the user clicks anywhere within the
browser window */
• </script>
As a method attached
to the element
• <script>
• window.addEventListener("click", myFunction); /*
myFunction will run when the user clicks anywhere
within the browser window */
• </script>
Using
addEventListener
The DOM is a
collection of
nodes:
• Element nodes
• Attribute nodes
• Text nodes
Document Object Model
The Document Object Model, or DOM, represents
the web page that is loaded into the browser using a
series of objects.The main object is the document
object, which in turn contains several other child
objects.
• <html>
• <head>
• <title>Document title</title>
• <meta charset="utf-8">
• </head>
• <body>
• <div>
• <h2>Subhead</h2>
• <p>Paragraph text with a
<a href="foo.html">link</a> here.</p>
• </div>
• <div>
• <p>More text here.</p>
• </div>
• </body>
• </html>
Example DOM tree
• Dot Notation
• In order to access the different objects in the DOM, you start with the doc
ument object, working down to the object that holds the data you are aft
er.
• Each object is separated by a period or full - stop character; hence, this is
known as a dot notation .
• For example the statement in the following example says to look on the p
age (document), find the element that has the id value “beginner”, find t
he HTML content within that element (innerHTML),
• document.getElementById( "beginner" ).innerHTML;
Accessing
DOM Nodes
• There are several methods for accessing nodes in the document.
• By element name
• getElementsByTagName()
• document.getElementsByTagName("p");
• By id attribute value
• getElementById()
• This method returns a single element based on that element’s ID (the value of its id
attribute), which we provide to the method as an argument:
• document.getElementById("lead-photo");
Ways forAccessing Nodes
• By class attribute value
• getElementsByClassName()
• This allows you to access nodes in the document based on
the value of a class attribute
• document.getElementsByClassName("column");
• By selector
• querySelectorAll()
• It allows you to access nodes of the DOM based on a CSS-style selector.
• document.querySelectorAll(".sidebar p");
• Accessing an attribute value
• getAttribute()
• Toget the value of an attribute attached to an element node, we call getAttribute()
with a single argument: the attribute name.
• document.getElementById("lead-image").getAttribute("src")
Ways forAccessing Nodes
• DOM also gives us several built-in methods for manipulating
elements their attributes, and their contents.
• setAttribute()
• It is used to set the value of element attributes, for example here it sets src
attribute to a new image name. This method requires two arguments: the a
ttribute to be changed and the new value for that attribute.
• document.getElementById("lead-image"). setAttribute("src", "lespaul.jpg");
• innerHTML
• Suppose we need a quick way of adding a paragraph of text to the first element
on our page with a class of intro:
• document.getElementsByClassName("intro"). innerHTML =“<p>This is our intro text</p>";;
• Style
• DOM also allows us to add, modify, or remove a CSS style from an element using the style property. It
works similarly to applying a style with the inline styleattribute.
• document.getElementById("intro").style.color = "#fff";
Manipulating
Nodes

Más contenido relacionado

La actualidad más candente

Java best practices
Java best practicesJava best practices
Java best practicesRay Toal
 
Extending the Xbase Typesystem
Extending the Xbase TypesystemExtending the Xbase Typesystem
Extending the Xbase TypesystemSebastian Zarnekow
 
XSLT and XPath - without the pain!
XSLT and XPath - without the pain!XSLT and XPath - without the pain!
XSLT and XPath - without the pain!Bertrand Delacretaz
 
More Little Wonders of C#/.NET
More Little Wonders of C#/.NETMore Little Wonders of C#/.NET
More Little Wonders of C#/.NETBlackRabbitCoder
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handlingSuite Solutions
 
PhD Presentation
PhD PresentationPhD Presentation
PhD Presentationmskayed
 
Twinkle: A SPARQL Query Tool
Twinkle: A SPARQL Query ToolTwinkle: A SPARQL Query Tool
Twinkle: A SPARQL Query ToolLeigh Dodds
 
Aspect-oriented programming in Perl
Aspect-oriented programming in PerlAspect-oriented programming in Perl
Aspect-oriented programming in Perlmegakott
 
Session 2 - Objective-C basics
Session 2 - Objective-C basicsSession 2 - Objective-C basics
Session 2 - Objective-C basicsVu Tran Lam
 
Hibernate training mumbai_hql
Hibernate training mumbai_hqlHibernate training mumbai_hql
Hibernate training mumbai_hqlvibrantuser
 
Visual Basics for Application
Visual Basics for Application Visual Basics for Application
Visual Basics for Application Raghu nath
 

La actualidad más candente (20)

Java best practices
Java best practicesJava best practices
Java best practices
 
Extending the Xbase Typesystem
Extending the Xbase TypesystemExtending the Xbase Typesystem
Extending the Xbase Typesystem
 
Javascript
JavascriptJavascript
Javascript
 
XSLT and XPath - without the pain!
XSLT and XPath - without the pain!XSLT and XPath - without the pain!
XSLT and XPath - without the pain!
 
More Little Wonders of C#/.NET
More Little Wonders of C#/.NETMore Little Wonders of C#/.NET
More Little Wonders of C#/.NET
 
Orms
OrmsOrms
Orms
 
Orms
OrmsOrms
Orms
 
JAVASCRIPT - LinkedIn
JAVASCRIPT - LinkedInJAVASCRIPT - LinkedIn
JAVASCRIPT - LinkedIn
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Hibernate in Nutshell
Hibernate in NutshellHibernate in Nutshell
Hibernate in Nutshell
 
Ot performance webinar
Ot performance webinarOt performance webinar
Ot performance webinar
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
 
PhD Presentation
PhD PresentationPhD Presentation
PhD Presentation
 
Twinkle: A SPARQL Query Tool
Twinkle: A SPARQL Query ToolTwinkle: A SPARQL Query Tool
Twinkle: A SPARQL Query Tool
 
PDF Localization
PDF  LocalizationPDF  Localization
PDF Localization
 
Aspect-oriented programming in Perl
Aspect-oriented programming in PerlAspect-oriented programming in Perl
Aspect-oriented programming in Perl
 
Session 2 - Objective-C basics
Session 2 - Objective-C basicsSession 2 - Objective-C basics
Session 2 - Objective-C basics
 
Hibernate training mumbai_hql
Hibernate training mumbai_hqlHibernate training mumbai_hql
Hibernate training mumbai_hql
 
Visual Basics for Application
Visual Basics for Application Visual Basics for Application
Visual Basics for Application
 
Xml
XmlXml
Xml
 

Similar a Lecture17 ie321 dr_atifshahzad_js

Similar a Lecture17 ie321 dr_atifshahzad_js (20)

Javascript part1
Javascript part1Javascript part1
Javascript part1
 
Wt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technologyWt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technology
 
Wt unit 2 ppts client side technology
Wt unit 2 ppts client side technologyWt unit 2 ppts client side technology
Wt unit 2 ppts client side technology
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
 
FYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptFYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III Javascript
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 
Web programming
Web programmingWeb programming
Web programming
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentals
 
Javascript sivasoft
Javascript sivasoftJavascript sivasoft
Javascript sivasoft
 
2javascript web programming with JAVA script
2javascript web programming with JAVA script2javascript web programming with JAVA script
2javascript web programming with JAVA script
 
Html JavaScript and CSS
Html JavaScript and CSSHtml JavaScript and CSS
Html JavaScript and CSS
 
AD215 - Practical Magic with DXL
AD215 - Practical Magic with DXLAD215 - Practical Magic with DXL
AD215 - Practical Magic with DXL
 
BITM3730 10-4.pptx
BITM3730 10-4.pptxBITM3730 10-4.pptx
BITM3730 10-4.pptx
 
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra  SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
SenchaCon 2016: Learn the Top 10 Best ES2015 Features - Lee Boonstra
 
JavaScript_III.pptx
JavaScript_III.pptxJavaScript_III.pptx
JavaScript_III.pptx
 
Php
PhpPhp
Php
 
BITM3730 10-3.pptx
BITM3730 10-3.pptxBITM3730 10-3.pptx
BITM3730 10-3.pptx
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 

Más de Atif Shahzad

Lecture04 computer applicationsie1_dratifshahzad
Lecture04 computer applicationsie1_dratifshahzadLecture04 computer applicationsie1_dratifshahzad
Lecture04 computer applicationsie1_dratifshahzadAtif Shahzad
 
Lecture03 computer applicationsie1_dratifshahzad
Lecture03 computer applicationsie1_dratifshahzadLecture03 computer applicationsie1_dratifshahzad
Lecture03 computer applicationsie1_dratifshahzadAtif Shahzad
 
Lecture01 computer applicationsie1_dratifshahzad
Lecture01 computer applicationsie1_dratifshahzadLecture01 computer applicationsie1_dratifshahzad
Lecture01 computer applicationsie1_dratifshahzadAtif Shahzad
 
Lecture02 computer applicationsie1_dratifshahzad
Lecture02 computer applicationsie1_dratifshahzadLecture02 computer applicationsie1_dratifshahzad
Lecture02 computer applicationsie1_dratifshahzadAtif Shahzad
 
Lecture02 computer applicationsie1_dratifshahzad
Lecture02 computer applicationsie1_dratifshahzadLecture02 computer applicationsie1_dratifshahzad
Lecture02 computer applicationsie1_dratifshahzadAtif Shahzad
 
Dr atif shahzad_sys_ management_lecture_agile
Dr atif shahzad_sys_ management_lecture_agileDr atif shahzad_sys_ management_lecture_agile
Dr atif shahzad_sys_ management_lecture_agileAtif Shahzad
 
Dr atif shahzad_sys_ management_lecture_10_risk management_fmea_vmea
Dr atif shahzad_sys_ management_lecture_10_risk management_fmea_vmeaDr atif shahzad_sys_ management_lecture_10_risk management_fmea_vmea
Dr atif shahzad_sys_ management_lecture_10_risk management_fmea_vmeaAtif Shahzad
 
Dr atif shahzad_engg_ management_module_01
Dr atif shahzad_engg_ management_module_01Dr atif shahzad_engg_ management_module_01
Dr atif shahzad_engg_ management_module_01Atif Shahzad
 
Dr atif shahzad_engg_ management_lecture_inventory models
Dr atif shahzad_engg_ management_lecture_inventory modelsDr atif shahzad_engg_ management_lecture_inventory models
Dr atif shahzad_engg_ management_lecture_inventory modelsAtif Shahzad
 
Dr atif shahzad_engg_ management_lecture_inventory management
Dr atif shahzad_engg_ management_lecture_inventory managementDr atif shahzad_engg_ management_lecture_inventory management
Dr atif shahzad_engg_ management_lecture_inventory managementAtif Shahzad
 
Dr atif shahzad_engg_ management_cost management
Dr atif shahzad_engg_ management_cost managementDr atif shahzad_engg_ management_cost management
Dr atif shahzad_engg_ management_cost managementAtif Shahzad
 
Dr atif shahzad_sys_ management_lecture_outsourcing managing inter organizati...
Dr atif shahzad_sys_ management_lecture_outsourcing managing inter organizati...Dr atif shahzad_sys_ management_lecture_outsourcing managing inter organizati...
Dr atif shahzad_sys_ management_lecture_outsourcing managing inter organizati...Atif Shahzad
 
Lecture16 ie321 dr_atifshahzad_css
Lecture16 ie321 dr_atifshahzad_cssLecture16 ie321 dr_atifshahzad_css
Lecture16 ie321 dr_atifshahzad_cssAtif Shahzad
 
Lecture15 ie321 dr_atifshahzad_html
Lecture15 ie321 dr_atifshahzad_htmlLecture15 ie321 dr_atifshahzad_html
Lecture15 ie321 dr_atifshahzad_htmlAtif Shahzad
 
Lecture14 ie321 dr_atifshahzad -algorithmic thinking part2
Lecture14 ie321 dr_atifshahzad -algorithmic thinking part2Lecture14 ie321 dr_atifshahzad -algorithmic thinking part2
Lecture14 ie321 dr_atifshahzad -algorithmic thinking part2Atif Shahzad
 
Lecture13 ie321 dr_atifshahzad -algorithmic thinking
Lecture13 ie321 dr_atifshahzad -algorithmic thinkingLecture13 ie321 dr_atifshahzad -algorithmic thinking
Lecture13 ie321 dr_atifshahzad -algorithmic thinkingAtif Shahzad
 
Lecture12 ie321 dr_atifshahzad - networks
Lecture12 ie321 dr_atifshahzad - networksLecture12 ie321 dr_atifshahzad - networks
Lecture12 ie321 dr_atifshahzad - networksAtif Shahzad
 
Lecture11 ie321 dr_atifshahzad -security
Lecture11 ie321 dr_atifshahzad -securityLecture11 ie321 dr_atifshahzad -security
Lecture11 ie321 dr_atifshahzad -securityAtif Shahzad
 
Lecture10 ie321 dr_atifshahzad
Lecture10 ie321 dr_atifshahzadLecture10 ie321 dr_atifshahzad
Lecture10 ie321 dr_atifshahzadAtif Shahzad
 
Lecture08 ie321 dr_atifshahzad
Lecture08 ie321 dr_atifshahzadLecture08 ie321 dr_atifshahzad
Lecture08 ie321 dr_atifshahzadAtif Shahzad
 

Más de Atif Shahzad (20)

Lecture04 computer applicationsie1_dratifshahzad
Lecture04 computer applicationsie1_dratifshahzadLecture04 computer applicationsie1_dratifshahzad
Lecture04 computer applicationsie1_dratifshahzad
 
Lecture03 computer applicationsie1_dratifshahzad
Lecture03 computer applicationsie1_dratifshahzadLecture03 computer applicationsie1_dratifshahzad
Lecture03 computer applicationsie1_dratifshahzad
 
Lecture01 computer applicationsie1_dratifshahzad
Lecture01 computer applicationsie1_dratifshahzadLecture01 computer applicationsie1_dratifshahzad
Lecture01 computer applicationsie1_dratifshahzad
 
Lecture02 computer applicationsie1_dratifshahzad
Lecture02 computer applicationsie1_dratifshahzadLecture02 computer applicationsie1_dratifshahzad
Lecture02 computer applicationsie1_dratifshahzad
 
Lecture02 computer applicationsie1_dratifshahzad
Lecture02 computer applicationsie1_dratifshahzadLecture02 computer applicationsie1_dratifshahzad
Lecture02 computer applicationsie1_dratifshahzad
 
Dr atif shahzad_sys_ management_lecture_agile
Dr atif shahzad_sys_ management_lecture_agileDr atif shahzad_sys_ management_lecture_agile
Dr atif shahzad_sys_ management_lecture_agile
 
Dr atif shahzad_sys_ management_lecture_10_risk management_fmea_vmea
Dr atif shahzad_sys_ management_lecture_10_risk management_fmea_vmeaDr atif shahzad_sys_ management_lecture_10_risk management_fmea_vmea
Dr atif shahzad_sys_ management_lecture_10_risk management_fmea_vmea
 
Dr atif shahzad_engg_ management_module_01
Dr atif shahzad_engg_ management_module_01Dr atif shahzad_engg_ management_module_01
Dr atif shahzad_engg_ management_module_01
 
Dr atif shahzad_engg_ management_lecture_inventory models
Dr atif shahzad_engg_ management_lecture_inventory modelsDr atif shahzad_engg_ management_lecture_inventory models
Dr atif shahzad_engg_ management_lecture_inventory models
 
Dr atif shahzad_engg_ management_lecture_inventory management
Dr atif shahzad_engg_ management_lecture_inventory managementDr atif shahzad_engg_ management_lecture_inventory management
Dr atif shahzad_engg_ management_lecture_inventory management
 
Dr atif shahzad_engg_ management_cost management
Dr atif shahzad_engg_ management_cost managementDr atif shahzad_engg_ management_cost management
Dr atif shahzad_engg_ management_cost management
 
Dr atif shahzad_sys_ management_lecture_outsourcing managing inter organizati...
Dr atif shahzad_sys_ management_lecture_outsourcing managing inter organizati...Dr atif shahzad_sys_ management_lecture_outsourcing managing inter organizati...
Dr atif shahzad_sys_ management_lecture_outsourcing managing inter organizati...
 
Lecture16 ie321 dr_atifshahzad_css
Lecture16 ie321 dr_atifshahzad_cssLecture16 ie321 dr_atifshahzad_css
Lecture16 ie321 dr_atifshahzad_css
 
Lecture15 ie321 dr_atifshahzad_html
Lecture15 ie321 dr_atifshahzad_htmlLecture15 ie321 dr_atifshahzad_html
Lecture15 ie321 dr_atifshahzad_html
 
Lecture14 ie321 dr_atifshahzad -algorithmic thinking part2
Lecture14 ie321 dr_atifshahzad -algorithmic thinking part2Lecture14 ie321 dr_atifshahzad -algorithmic thinking part2
Lecture14 ie321 dr_atifshahzad -algorithmic thinking part2
 
Lecture13 ie321 dr_atifshahzad -algorithmic thinking
Lecture13 ie321 dr_atifshahzad -algorithmic thinkingLecture13 ie321 dr_atifshahzad -algorithmic thinking
Lecture13 ie321 dr_atifshahzad -algorithmic thinking
 
Lecture12 ie321 dr_atifshahzad - networks
Lecture12 ie321 dr_atifshahzad - networksLecture12 ie321 dr_atifshahzad - networks
Lecture12 ie321 dr_atifshahzad - networks
 
Lecture11 ie321 dr_atifshahzad -security
Lecture11 ie321 dr_atifshahzad -securityLecture11 ie321 dr_atifshahzad -security
Lecture11 ie321 dr_atifshahzad -security
 
Lecture10 ie321 dr_atifshahzad
Lecture10 ie321 dr_atifshahzadLecture10 ie321 dr_atifshahzad
Lecture10 ie321 dr_atifshahzad
 
Lecture08 ie321 dr_atifshahzad
Lecture08 ie321 dr_atifshahzadLecture08 ie321 dr_atifshahzad
Lecture08 ie321 dr_atifshahzad
 

Último

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456KiaraTiradoMicha
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyAnusha Are
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 

Último (20)

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

Lecture17 ie321 dr_atifshahzad_js

  • 1. DR ATIF SHAHZAD Fundamentals of Computer Systems IE-321 LECTURE #17
  • 2. RECAP Logic Logical variables Conditional, Negation, Contrapositive,Biconditional AND, OR,NOT,XOR Logic gates TruthTables BooleanAlgebra Examples Q&A MicrosoftVisio Microsoft Project Spreadsheet Concepts: Using Microsoft Excel Creating Charts in Microsoft Excel Debugging Concepts Using Microsoft Excel Presentation Concepts Using Microsoft PowerPoint Image Concepts Memory Memory Cell CPU Register Program Counter Fetch-Execute Cycle Q&A File Management Word Processing Basics Using MicrosoftWord MicrosoftWord Layout and Graphics Features Making and using compressed Files WinZip, 7Zip Notepad++ Wordpad Adobe acrobat Sumatra PDF MathType Database Flat & Relational Database DBMS Tables & Fields Creating Tables in Access Design view and Data Sheet View Primary Key & Foreign key Relationships & ER Diagram Queries &Simple SQL Cyber Security Security Problems Interception Spoofing Falsification Repudiation Security Technologies Encryption MAC Data Model Algorithm Ingredients Variables Constructs Pseudocode Flowchart Symbols Flowcharting examples Q&A
  • 7. HTML • provides a page with structure and CSS • provides a page with appearance, JavaScript • provides a page with behavior. Javascript
  • 8. JavaScript provides the ability to add interactivity to a website help enrich the user experience. Javascript
  • 9. JavaScript doesn’t need to be run through any form of compiler that interprets our human- readable code into something the browser can understand. The browser effectively reads the code and interprets it on the fly. Javascript
  • 10. JavaScript 9/27/2018 Dr.AtifShahzad 10 JavaScript on the web lives inside the HTML document. In HTML, JavaScript code must be inserted between <script> and </script> tags: <script> ... </script>
  • 11. JavaScript 9/27/2018 Dr.AtifShahzad 11 JS can be placed in the HTML page's <body> section <head> section.
  • 13. Adding Javascript to a Page Like CSS, you can embed a script right in a document or keep it in an external file and link it to the page. Embedded Script External scripts
  • 14. Adding Javascript to a Page • To embed a script on a page, just add the code as thecontent of a script element: • <script> • … JavaScript code goes here • </script> Embedded Script • The other method uses the src attribute to point to a script file (with a .js suffix) by its URL. In this case, the script element has no content. • <script src="my_script.js"></script> External scripts
  • 15. Adding Javascript to a Page <html> <head> </head> <body> <script> document.write("<h1>HelloWorld!</h1>"); </script> </body> </html>
  • 16. The placement depends on when it should be executed. Javascript can be placed for scripts either in the head of the document or at the very end of the body. Script Placement • The best place to reference JavaScript files is right before the closing</bo dy> tag so that the JavaScript file is loaded after all of the HTML has been parsed. • Putting it in header blocks the rendering of the page unless the whole file is downloaded and executed, so moving the script to the bottom improves the perceived performance. • However, at times, JavaScript is needed to help render HTML and determine it’s behavior, thus may be referenced within a document’s head
  • 17. The placement depends on when it should be executed. Javascript can be placed for scripts either in the head of the document or at the very end of the body. Script Placement JS in head <html> <head> <script> </script> </head> <body> </body> </html> JS in body <html> <head> </head> <body> <script> </script> </body> </html>
  • 18. Adding Javascript to a Page <html> <head> <title></title> <script type="text/javascript"> alert("This is an alert box!"); </script> </head> <body> </body> </html>
  • 19. External JavaScript Scripts can also be placed in external files. External scripts are useful and practical when the same code is used in a number of different web pages. JavaScript files have the file extension.js
  • 20. External JavaScript <html> <head> <title> </title> <script src=“IE321.js"></script> </head> <body> </body> </html> alert("This is an alert box!"); IE321.js
  • 21. Statements Comments Variables Data types Arrays Comparison Operators If/else Statements Loops Functions Variable Scope Javascript Basics
  • 22. A statement is a command that tells the browser what to do. A script is made up of a series of statements. For example,alert("Thankyou.");is a statement. The semicolon at the end indicates the end of the statement. Statement
  • 23. Single-line comments, use two slash characters (//) at the beginning of the line. // This is a single-line comment. Multiple-line comments use the same syntax that you’ve seen in CSS. Everything within the /* */ characters is ignored by the browser. Comments /* This is a multi-line comment. Anything between these sets of characters will be completely ignored when the script is executed. This form of comment needs to be closed. */
  • 24. alert() Alerts the user with some Message Used for OUTPUT 9/27/2018 Dr.AtifShahzad 24 alert("Thanks for visiting");
  • 25. document.write() document.write("Another day"); Used for OUTPUT 9/27/2018 Dr.AtifShahzad 25 document.write("Thanks for visiting");
  • 27. prompt() The prompt() method takes two parameters. The first is the label, which you want to display in the text box. The second is a default string to display in the text box (optional). 9/27/2018 Dr.AtifShahzad 27 A prompt box is often used to have the user 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 the input value. If the user clicks OK, the box returns the input value. If the user clicks Cancel, the box returns null. var user = prompt("Please enter your name"); alert(user); Used for INPUT
  • 28. A variable is like an information container. You give it a name and then assign it a value, which can be a number, text string, an element in the DOM, or a function. The following declaration creates a variable with the name “foo” and assigns it the value 5: var foo = 5; Variables
  • 29. Undefined The simplest of these data types is “undefined.” If we declare a variable by giving it a name but no value, that variable contains a value of “undefined.” var foo; alert(foo); // This will open a dialog containing "undefined". Null Assigning a variable of “null” (again, case-sensitive) simply says,“Define this variable, but give it no inherent value.” var foo = null; alert(foo); // This will open a dialog containing "null". Data types
  • 30. Numbers You can assign variables numeric values. var foo = 5; alert(foo); // This will open a dialog containing "5". The word “foo” now means the exact same thing as the number five. Because JavaScript is “loosely typed,” we don’t have to tell our script to treat the variable foo as the number five. Data types
  • 31. Numbers We can use classic mathematical notation: +,-, *, and / for plus, minus, multiply, and divide, respectively. In this example, we use the plus sign (+) to add foo to itself (foo + foo). var foo = 5; alert(foo + foo); // This will alert "10". Data types
  • 32. Strings a line of text. Enclosing characters in a set of single or double quotes indicates that it’s a string. var foo = "five"; alert( foo ); // This will alert "five" The variable foo is now treated exactly the same as the word “five”. Data types
  • 33. Strings When the plus sign is used with strings, it sticks the strings together (called concatenation) into one long string, as shown in this example. var foo = "bye" alert (foo + foo); // This will alert "byebye“ var foo = "5"; alert( foo + foo ); // This will alert "55“ var foo = "five"; var bar = 5; alert( foo + bar ); // This will alert "five5" Data types
  • 34. Strings var mystring1 = "I am learning "; var mystring2 = "JavaScript in IE321."; document.write(mystring1 + mystring2); Data types
  • 35. Boolean assign a variable a true or false value. Boolean values use the true and false keywords built into JavaScript, so quotation marks are NOT necessary. var foo = true; // The variable "foo" is now true Data types
  • 38. Increment/decrement Operators Increment ++ • The increment operator increments the numeric value of its operand by one. If placed before the operand, it returns the incremented value. If placed after the operand, it returns the original value and then increments the operand. Decrement -- • The decrement operator decrements the numeric value of its operand by one. If placed before the operand, it returns the decremented value. If placed after the operand, it returns the original value and then decrements the operand. 9/27/2018 Dr.AtifShahzad 38
  • 40. A group of multiple values (called members) that can be assigned to a single variable. It is a way to store a list of items, or values. The values in an array are said to be indexed, meaning you can refer to them by number according to the order in which they appear in the list.The first member is given the index number 0, the second is 1, and so on. Arrays
  • 41. For example,values in the array foo can be accessed by referencing their index number: var foo = [5, "five", "5"]; alert( foo[0] ); // Alerts "5" alert( foo[1] ); // Alerts "five" alert( foo[2] ); // Also alerts "5" Arrays
  • 42. To compare two values, JavaScript evaluates the statement and gives us back a Boolean value depending on whether the statement is true or false. • == Is equal to != Is not equal to • === Is identical to (equal to and of the same data type) !== Is not identical to > Is greater than >= Is greater than or equal to < Is less than <= Is less than or equal to Comparison Operators
  • 43. alert( 5 == 5 ); // This will alert "true" alert( 5 != 6 ); // This will alert "true" alert( 5 < 1 ); // This will alert "false" Comparison Operators
  • 44. If/else statements are how we get JavaScript to ask itself a true/false question. structure of a conditional statement: if( true ) { // Do something. } If/else statements
  • 45. var foo = [5, "five", "5"]; if( foo[1] === "five" ) { alert("This is the word five, written in plain English.");} In this case, the alert would fire because the foo variable with an index of 1 (the second in the list) is identical to “five”. var test = "testing"; if( test == "testing" ) { alert( "You haven't changed anything." ); } else { alert( "You've changed something!" ); } If/else statements
  • 46. switch (expression) { case n1: statements break; case n2: statements break; default: statements } Switch Statement when you need to test for multiple conditions
  • 47. var day = 2; switch (day) { case 1: document.write("Monday"); break; case 2: document.write("Tuesday"); break; case 3: document.write("Wednesday"); break; default: document.write("Another day"); } // Outputs "Tuesday" Switch Statement
  • 48. There are cases in which we’ll want to go through every item in an array and do something with it, several ways to write a loop, but the for method is one of the most popular. Loops
  • 49. basic structure: for( initialize the variable; test the condition; alter the value; ) { // do something } Here is an example of a for loop in action. for( var i = 0; i <= 2; i++ ) { alert( i ); //This loop will trigger three alerts, reading "0", "1“, and "2" respectively. } for Loops
  • 50. check each item in an array” example. var items = ["foo", "bar", "baz"];// First we create an array. for( var i = 0; i <= items.length; i++ ) { alert( items[i] ); //This will alert each item in the array. } For Loop--Exp items.length •Instead of using a number to limit the number of times the loop runs, we’re using a property built right into JavaScript to determine the “length” of our array, which is the number of items it contains. .length items[i] •We can use i variable inside of the loop to reference each index of the array.
  • 51. basic structure: while (condition) { code block } while Loop The while loop repeats through a block of code, as long as a specified condition is true.
  • 52. Example: var i=0; while (i<=10) { document.write(i + "<br />"); i++; } while Loop- Exp
  • 53. A function is a bit of code that doesn’t run until it is referenced or called. alert() is a function built into our browser. Functions
  • 54. “out-of-the-box” (native JavaScript functions) (custom functions). Native functions Types of Functions
  • 56. hundreds of predefined functions built into JavaScript, including: alert(), confirm(), and prompt() » These functions trigger browser-level dialog boxes. Date() : Returns the current date and time. parseInt("123"):This function will, among other things, take a string data type containing numbers and turn it into a number data type.The string is passed to the function as an argument. SetTimeout(functionName, 5000):Will execute a function after a delay.The function is specified in the first argument, and the delay is specified in milliseconds in the second (in the example, 5000 milliseconds equals 5 seconds). Native functions
  • 57. To create a custom function, we type the function keyword followed by a name for the function, followed by opening and closing parentheses, followed by opening and closing curly brackets. function name() { // Our function code goes here. } Custom functions
  • 58. There are times when you’ll want a variable that you’ve defined within a function to be available anywhere throughout your script. Other times, you may want to restrict it and make it available only to the function it lives in. This notion of the availability of the variable is known as its scope. Variable Scope
  • 59. A variable that can be used by any of the scripts on your page is globally scoped. A variable that’s available only within its parent function is locally scoped. JavaScript variables use functions to manage their scope. If a variable is defined outside of a function, it will be globally scoped and available to all scripts. Variable Scope
  • 60. When you define a variable within a function and you want it to be used only by that function, you can flag it as locally scoped by preceding the variable name with the var keyword. var foo = "value"; To expose a variable within a function to the global scope, we omit the var keyword and simply define the variable: foo = "value"; Local vs Global variable
  • 61. A variable declared outside a function, becomes GLOBAL. var carName = "Volvo"; // code here can use carName function myFunction() { // code here can use carName } Local vs Global variable
  • 62. • <!DOCTYPE html> • <html> • <body> • <p onclick="myFunction(),myFunction1();" >Th e local variable carName cannot be ac cessed from code outside the function:</p > • <p id="demo"></p> • <script src="function.js"></script> • </body> • </html> • function myFunction() { • var carName = "Volvo"; • } • function myFunction1() • { • document.getElementById("demo").inner HTML ="The type of carName is " + typeof carName; • } Local vs Global Variables
  • 63. The return statement stops the execution of a function and returns a value from that function. Return Statement
  • 64. function addNumbers(a,b) { return a + b; } Any reference you make to that function gives you the result of the function. alert( addNumbers(2,5) ); //Alerts "7“ Return Statement
  • 65. What will be the output of the following function function bar() { return 3; alert(“displays alert."); } var x = bar (); alert(x) Return Statement
  • 66.
  • 67. 9/27/2018 Dr.AtifShahzad 67 NEVER hesitate to contact should you have any question Dr.Atif Shahzad
  • 68. <button id="btn" onclick="googleRedirect()">Redirect to Google!</button> Browser Object Model JavaScript gives you access to and the ability to manipulate the parts of the browser window itself. For example, we can make the browser to redirect to some URL on the click of a button. You then call this function from the < body > element’ s onclick event, like so: Then we can use this function to indicate where this browser should be redirected on the click of a button. To do this, first you need to add a function in a javascript file that is going to be triggered when the button is clicked, function googleRedirect() { window.location.assign("http://www.w 3schools.com"); }
  • 69. Window Properties/ Methods In JavaScript, the browser is known as the window object. The window object has a number of properties and methods that we can use to interact with it.
  • 70. Windows Events For example, the onload event handler triggers a script when the document loads. Similarly onclick and onmouseover handlers trigger a script when the user clicks or mouses over an element, respectively. An event is an action that can be detected with JavaScript, such as when the document loads or when the user clicks on an element or just moves her mouse over it. In scripts, an event is identified by an event handler.
  • 72. • There are three ways we can apply event handlers within a webpage. Applying Event Handlers • <body onclick="myFunction();"> /* myFunction will now run when the user clicks anything within 'body' */As an HTML attribute • <script> • window.onclick = myFunction; /* myFunction will run when the user clicks anywhere within the browser window */ • </script> As a method attached to the element • <script> • window.addEventListener("click", myFunction); /* myFunction will run when the user clicks anywhere within the browser window */ • </script> Using addEventListener
  • 73. The DOM is a collection of nodes: • Element nodes • Attribute nodes • Text nodes Document Object Model The Document Object Model, or DOM, represents the web page that is loaded into the browser using a series of objects.The main object is the document object, which in turn contains several other child objects.
  • 74. • <html> • <head> • <title>Document title</title> • <meta charset="utf-8"> • </head> • <body> • <div> • <h2>Subhead</h2> • <p>Paragraph text with a <a href="foo.html">link</a> here.</p> • </div> • <div> • <p>More text here.</p> • </div> • </body> • </html> Example DOM tree
  • 75. • Dot Notation • In order to access the different objects in the DOM, you start with the doc ument object, working down to the object that holds the data you are aft er. • Each object is separated by a period or full - stop character; hence, this is known as a dot notation . • For example the statement in the following example says to look on the p age (document), find the element that has the id value “beginner”, find t he HTML content within that element (innerHTML), • document.getElementById( "beginner" ).innerHTML; Accessing DOM Nodes
  • 76. • There are several methods for accessing nodes in the document. • By element name • getElementsByTagName() • document.getElementsByTagName("p"); • By id attribute value • getElementById() • This method returns a single element based on that element’s ID (the value of its id attribute), which we provide to the method as an argument: • document.getElementById("lead-photo"); Ways forAccessing Nodes
  • 77. • By class attribute value • getElementsByClassName() • This allows you to access nodes in the document based on the value of a class attribute • document.getElementsByClassName("column"); • By selector • querySelectorAll() • It allows you to access nodes of the DOM based on a CSS-style selector. • document.querySelectorAll(".sidebar p"); • Accessing an attribute value • getAttribute() • Toget the value of an attribute attached to an element node, we call getAttribute() with a single argument: the attribute name. • document.getElementById("lead-image").getAttribute("src") Ways forAccessing Nodes
  • 78. • DOM also gives us several built-in methods for manipulating elements their attributes, and their contents. • setAttribute() • It is used to set the value of element attributes, for example here it sets src attribute to a new image name. This method requires two arguments: the a ttribute to be changed and the new value for that attribute. • document.getElementById("lead-image"). setAttribute("src", "lespaul.jpg"); • innerHTML • Suppose we need a quick way of adding a paragraph of text to the first element on our page with a class of intro: • document.getElementsByClassName("intro"). innerHTML =“<p>This is our intro text</p>";; • Style • DOM also allows us to add, modify, or remove a CSS style from an element using the style property. It works similarly to applying a style with the inline styleattribute. • document.getElementById("intro").style.color = "#fff"; Manipulating Nodes