SlideShare ist ein Scribd-Unternehmen logo
1 von 60
HTML/JavaScript/CSS
History
 What is the relationship between:
 SGML
 HTML
 XHTML
 CSS
 JavaScript
History
 Markup
 Annotations instructing how the document
should appear in print
 Word processors use different markup
schemes
 SGML
IBM - Standard Generalized Markup Language
Markup instructions stored with ASCII file
 Any computer could render document
 Lilly Example
History
 HTML
 Tim Berners-Lee created HTML – subset of
SGML
 Not platform or application specific
 Only server software needed to publish file s
on the net

 Structure versus content
 Browser parses HTML file into a tree
History
 Sample HTML File
 <FONT SIZE=14 FACE=Swing>
 <B>Bryan Moore</B><BR>
 </FONT>
 <FONT SIZE=12 FACE=Textile>
 1234 Sunset Ave. <BR>
 Walla Walla, WA 12345 <BR>
 (123)123.4567<BR>
 </FONT>
Web Applications and Real World Design - Knuckles
History
Browser parse tree

Web Applications and Real World Design - Knuckles
History
 Problems with extracting data
 Need to write a computer program to extract
the names and addresses by selecting text
strings following font tags

 Content and structure of document become
intertwined
 Not the intention of SGML and original HTML
 Cascading Style Sheets
 Attempt to separate content and style
History
 CSS
 Can alter the look of entire file with a simple
coding change
 Can keep styles in an external file
 Increases the knowledge needed to code
pages
Initial rationale of HTML was to appeal to the
masses
History
Parse tree using CSS

Still need to reference
Information based on
“second string after BR”
Information is not
meaningful

Web Applications and Real World Design - Knuckles
History
 Extensible Markup Language XML
 Extensible- can create own tags
 Complete separation of content and style

Web Applications and Real World Design - Knuckles
History
 Releases
 HTML 4.0 1997
 XML 1.0 1998

 XML and HTML need to better cooperate
 XHTML 1.0 2000

 XHTML
 Contains elements and attributes of HTML
 Elements must have closing tags
 Lowercase
 Attributes must have values
 Attributes in single or double quotes
 http://www.w3schools.com/xhtml/default.asp
HTML Forms and JavaScript
 Client Server Model
 Client Side Processing
 JavaScript downloaded from web page and processed by
the client – typically form checking
 JavaScript can interact directly with form data

 Server Side processing
 Information from a form sent to server for processing
 PHP Perl C++
 Server can interact directly with the form data
HTML Forms and JavaScript
 JavaScript
 HTML files are text files
 JavaScript is interpreted not compiled
 Object oriented
HTML forms are objects and can be manipulated
via JavaScript
Dynamic HTML – merger of JavaScript and
HTML

 Different implementations of DHTML by
software companies
What is JavaScript


Scripting language (object-oriented)
 Lightweight programming language developed by Netscape
 Interpreted, not compiled



Designed to be embedded in browsers









Ideal for adding interactivity to HTML pages
Detect browser versions
Work with info from user via HTML forms
Create cookies
Validate form data
Read and write HTML elements

Supported by all major browsers
 Internet Explorer has JScript (started in IE3)
 http://www.faqts.com/knowledge_base/view.phtml/aid/1380



It’s free, no license required
What is JavaScript
 Syntax is similar to Java, but it’s not Java per se
 Usually JavaScript code is embedded within HTML
code using the script tag:
 Can have more than one pair of script tags in a page
 Semicolons: C++ and JAVA require them but in
JavaScript it’s optional
What is JavaScript
 HelloWorld example program…


<html>











<head><title>JavaScript HelloWorld!
</title></head>
<body>
<script language="JavaScript">
document.write('Javascript says "Hello
World!"')
</script>
</body>

</html>

 Let’s open it in the browser
What is JavaScript
 Javascript can be located in the head, body
or external file
 Head section
Ensures script is loaded before trigger event

 Body section
Script executes when body loads

 External
Allows scripts to run on several pages

 Examples:
http://www.w3schools.com/js/js_whereto.asp
What is JavaScript
 JavaScript statements in head write to the
beginning of the body section but don’t violate
HTML code already there.
 JavaScript statements in body write based on
their location
 JavaScript interpreted first then HTML
interpreted second
 Document.write writes to the HTML document
not the web page
What is JavaScript












<html>
<head>
<script language=“JavaScript”>
document.write (“<b> This is first </b>);
</script>
</head>
<body>
Now where does this print on the web page???? <br />
<script language=“JavaScript”>
document.write ( “This might be last?”)
</script>




</body>
</html>



Lets See what the answer is!
What is JavaScript
 Now, let JavaScript generate HTML for us…
 <html>

<head><title>JavaScript HelloWorld!</title></head>

<body>

<script laguage="JavaScript">


document.write("<h2>Javascript-Generated output:</h2>
<p>This paragraph generated by JavaScript</p>
 <p>It can even insert an image</p>
 <img src='../assigns/RayWeb/images/cathedral.jpg' />")


</script>

</body>
 </html>

 Let’s open it in the browser
Identifier Etiquette
 Identifier– The name of a variable (or function)
 Starts with a letter, can contains digits & underscores
 Case Sensitive!!
 Should be meaningful to someone reading your code

 Good: accountBalance, amountDue
 Bad:

bal, due,

 Just plain wrong: 2bOrNotToBe, +var, total-value
Variables
 Must declare variables before they’re used in the
program
 Declare at the top of the program & terminate each
statement with ‘;’
 Intialize variables when appropriate
 Local variables (declared within a function) destroyed
after function exit.
 Can only be accessed within the function

 Example – Note Assignments
 var candyBarPrice = 2.50;
 var taxRate = .075;
 var candyBarsPurchased;
Assignment Operator
 Assignment ‘looks like’ equal sign but does NOT
behave like it
 subTotal = subTotal + 1.50
 subTotal ‘is assigned the value’ that is currently in
subTotal plus the value of 1.50
Expressions
 An expression is a statement that describes a
computation
 Usually look like algebra formulas
 total = subTotal * taxRate

 Operators (+, -, *, /, etc.) have different levels
of precedence, similar to algebra
 Don’t rely on it! For clarity, use parentheses

 w3Schools operator reference page
Conditional Statements--if
if (some boolean expression is true){
execute the statements within
the curly braces, otherwise skip to the
first statement after the closing brace
}
Resume execution here in either case
Conditional Statements– if/else
if (some boolean expression is true){
execute these statements, otherwise
skip to ‘else’ clause
}
else {
execute these statements if boolean
expression is false
}
Resume execution here in either case
Conditional Test Program
 Diagnostic messages indicate flow of control
1.
2.
3.
4.

var variable1 = 1; var variable2 = 2;

1.
2.

if(variable1 > variable2){

if(variable1 >= 0){
document.write(“<p> 1 is greater than 0

</p>");
5.
}
6.
document.write(“<p>Resuming execution after
'if'
7.
statement</p>");
8.

3.
4.
5.
6.
•

document.write(“<p>1 is greater than
2</p>");
}
else {
document.write(“<p>2 is greater than
1</p>");
}
document.write("Resuming execution after
Strings
 Strings are sequences of keyboard characters
enclosed in quotes


“Hello World” or ‘Hello World’

 Variables can hold strings
 var greeting = “Hello World”

 String can be empty, i.e., contain no characters
 var myAnswer = “”

 Use ‘’ (escape symbol) to ‘type’ prohibited characters
 b for backspace, n for newline, t for tab, ” for double
quote
JavaScript Functions – Basic
Principles
 Abstraction
 Experience has taught us that much code is
duplicated throughout program
 Functions let us write the functionality once,
then reuse it
JavaScript Functions – Basic
Principles
 Encapsulation
 Functions encapsulate a specific capability or feature
 Function name allows us to access a function in our
program

 Parameterization
 We can customize the function’s result by passing in
different values each time we use it

 Must use functions to write serious software!
JavaScript Functions – Basic
Principles
 Reasons to use functions
 Ease of communication
 Problem simplification
 Easier construction
 Code readability
 Reusability
 Maintainability

 In JS, functions are the primary encapsulation
mechanism
JavaScript Functions – Syntax
 JS function syntax
function myFunctionName (list of parameters) {
….JS code here…
}
JavaScript Functions -- Issues
 Key issues about using functions
 Naming functions
 Passing in parameters
 Using local variables within functions
 How to call (i.e., invoke) functions
 How to handle a function’s return value
 Where to put JS functions in your webpage
JavaScript Functions – Naming
 Function names
 Name describes what function does
 Name is an identifier, so follow JS identifier syntax
rules & course coding standards

 Example,
findMaxValue(‘put some parameters here’)
JavaScript Functions -- Parameters
 Passing parameters to the function
 Parameters provide functions with input
 Implicitly declared variables that can be accessed by
code within function body
 You provide actual input values when you call the
function
 Parameters are named variables separated by
commas

 Example,
function findMaxValue(num1, num2, num3)
JavaScript Functions – Where to
put?
 Put functions within <script>….</script> tags within
the <head> section of the web page
<head>
<script language=“JavaScript”>
declare functions here….
</script>
</head>
JavaScript Functions – Local
Variables
 If needed, you can declare local variables within a
function
 local variable is visible only within the function body
after it’s declared
 Commonly used to store results of an intermediate
calculation
JavaScript Functions – Local
Variables
function findMaxValue(num1, num2,num3) {
var tempMax; //local var
if (num1 >= num2) {
tempMax = num1;
}
else {
tempMax = num2;
}
if(num3 >= tempMax) {
tempMax = num3;
}
return tempMax;
} //end function
JavaScript Functions -- Calling
 To call a function from your program, add a
statement that contains the function name with
values for the parameters the function requires
 Example…somewhere in the <body>….,
var x = 1, y = 4, z = 2;
findMaxValue(x, y, z);

 What value does the function return?
 What happens with the result?
JavaScript Functions -- Return
 Return keyword tells function to return some value
and exit immediately
 Function can have multiple return statements but only
1 can be executed in any given function call
 Normally used to return the final result of a
calculation to the calling program
 For an example, see findMaxValue function
JavaScript Functions -- Return
 Good Example
 Uses var maxNumber in calling program
 Function’s return value is assigned to maxNumber
 Display of maxNumber has correct value for inputs

 Code snippet
 var x = 1, y = 4, z = 2;
var maxNumber = findMaxNumber(x, y, z);
document.write(“The maximum is: “ + maxNumber);
JavaScript Functions – Parameter
Sequence


1.
2.
3.
4.
5.
6.
7.

1.
2.

When calling functions, must enter parameters in same order
as specified in function argument list.

function calculateDensity(height, width, depth, mass){
var volume = height * width * depth;
var density = mass / volume;
return density;
}
……………………………………………….
var hth = 2, wth = 3, dth = 4, mass = 10;
var result = calculateDensity(2, 10, 3, 4);
//returns .07 but correct answer is .42!!!
JavaScript Functions – Global
Variables
 Global variables are those declared outside of
functions
 Global variables are ‘visible’ from anywhere in the
program, including inside functions
var globalHello = “Hello!”;
function writeHello() {
document.write(globalHello);
}
// outputs “Hello!”
Example program
JavaScript Functions – Testing
 Test each function thoroughly before proceeding with
next programming task
 Using multiple sets of inputs, be sure to test all
possible outcomes
 For each test, be sure calling program is properly
handling return values
JavaScript Functions – Debugging
 Use diagnostic output statements to trace program
execution
 Good places for diagnostic outputs
 Just before entering function
 Immediately upon entering function
 Before/In/After complex logic or computation
 Just before function return statement
 Immediately after function returns to calling program
JavaScript Functions
 Built-In Functions
 Prompt
 Alert
 Confirm

 http://www.w3schools.com/js/js_popup.asp
JavaScript and HTML Forms
 JavaScript Objects
 Var truck = new Object();
 Expression on right is a constructor
 Properties
truck.color=“white”
document.write(color);

 Primitives
 In JavaScript variable primitive types are
number, string and Boolean
JavaScript and HTML Forms
 Object Model for the Browser Window
 Compound object structure is created when a
web page loads into a browser
Hierarchy

 Window is an object, the HTML document is
an object and its elements are objects
 These objects have primitives associated with
them
JavaScript and HTML Forms
 window [closed, location]
history [length]
document [bgColor, fgColor, URL,
lastmodified,linkColor, vlinkColor]





images [properties]
links [properties]
frames [properties]
forms [properties]
JavaScript and HTML Forms
 Window object is parent of structure
 window.closed is primitive that is Boolean
 window.location primitive contains string of the URL of
the HTML file
 window.document object is primary focus

 When web page is loaded the HTML elements assign
values to most of these window.document primitives
 Often the word window is excluded as in
document.write but need it if referring to multiple
open windows
 Properties can also be objects
JavaScript and HTML Forms



















<HTML>
<HEAD>
<TITLE>Document Properties</TITLE>
<SCRIPT LANGUAGE=JavaScript><!-document.write(closed);
document.write("<BR>"+ document.bgColor);
document.write("<BR>"+document.fgColor);
document.write("<BR>"+document.lastModified);
//--></SCRIPT>
</HEAD>
<BODY TEXT="#0000FF" BGCOLOR="#FFFFCC">
<P>Blue text on a yellow background.<BR>
<SCRIPT LANGUAGE=JavaScript><!-document.write("<BR>"+ document.bgColor);
document.write("<BR>"+document.fgColor);
//--></SCRIPT>
</BODY>
</HTML>
Interactive Programming on the Internet Knuckles
JavaScript and HTML Forms
 false
#ffffff
#000000
01/10/2001 17:18:30 Blue text on a yellow
background.
#ffffcc
#0000ff

Interactive Programming on the Internet, Knuckles
JavaScript and HTML Forms
 Methods
 Behavior associated with an object
 Essentially functions that perform an action
 Some are built in and others user made

 Built-In Methods of the window object
 Confirm
 Alert
 Prompt
JavaScript and HTML Forms
 User Events
 An event occurs when a user makes a change
to a form element
Ex. Click a button, mouseover an image

 Detection of an event done by event handlers
 Event handler is an attribute of the HTML
button
 <form>
<input type=button value=“please click”
onclick=“function name()”>

 </form>
JavaScript and HTML Forms
<HTML>
<HEAD>
<SCRIPT LANGUAGE=JavaScript><!-function changecolor(){
document.bgColor="#ff0000";
}
//--></SCRIPT>
</HEAD>
<BODY>
<P><FORM >
<P><INPUT TYPE=button VALUE="Click Me"
onclick="changecolor()">
 </FORM>
 </BODY>
 </HTML>












Interactive Programming on the Internet ,Knuckles
JavaScript and HTML Forms
 Form Object
 Window.document.form
 A form is a property of the document but is
also an object
 Form elements are properties of a form and
are also objects
 Access to form’s properties is done through
the NAME attribute of the FORM tag
 Access to the properties of the form elements
is done through the NAME attributes of the
particular form element
JavaScript and HTML Forms

Interactive Programming on the Internet
,Knuckles
JavaScript and HTML Forms


























<HTML>
<HEAD>
<SCRIPT LANGUAGE=JavaScript><!-function plus(){
var n1;
var n2;
n1=document.addmult.num1.value;
n2=document.addmult.num2.value;
n1=parseFloat(n1);
n2=parseFloat(n2);
document.addmult.result.value=n1+n2;
}
function times(){
var n1;
var n2;
n1=document.addmult.num1.value;
n2=document.addmult.num2.value;
n1=parseFloat(n1);
n2=parseFloat(n2);
document.addmult.result.value=n1*n2;
}

Interactive Programming on the Internet ,Knuckles
















//--></SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFCC">
<P><FORM name=addmult>
<P>Enter a number in each field:
<INPUT TYPE=text NAME=num1 VALUE="" SIZE=5>
<INPUT TYPE=text NAME=num2 VALUE=""
SIZE=5><BR>
<INPUT TYPE=button VALUE="+" onclick="plus()">
<INPUT TYPE=button VALUE="*"
onclick="times()"><BR>
<INPUT TYPE=reset VALUE="Reset Form"><BR>
<TEXTAREA NAME=result ROWS=3 COLS=27
WRAP=virtual></TEXTAREA>
</FORM>
</BODY>
</HTML>
JavaScript and HTML Forms
Form for submitting info for server side processing

Interactive Programming on the Internet
,Knuckles
JavaScript and HTML Forms




























<HTML>
<HEAD>
<SCRIPT LANGUAGE=JavaScript><!-function verify(){
with(document.infoform){
if((fullname.value=="")||(address.value=="")||
(email.value=="")){
alert("You have left one or more fields blank. Please
supply the
necessary information, and resubmit the form.");
}
else {
display.value="The following information has been
added to our
guestbook:r"+fullname.value+"r"+ address.value +"r"
+email.value;
}
}
}
//--></SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFCC">
<P><FORM name=infoform>
<P><TABLE BORDER=0>
<TR>
<TD WIDTH=83>
<P>Name:
</TD>
<TD>
<P><INPUT TYPE=text NAME=fullname VALUE=""
SIZE=32>
</TD>
</TR>




<TR>





<TD WIDTH=83>
<P>Address:
</TD>
<TD>
<P><INPUT TYPE=text NAME=address VALUE=""
SIZE=32>
</TD>
</TR>
<TR>
<TD WIDTH=83>
<P>E-mail:
</TD>
<TD>
<P><INPUT TYPE=text NAME=email VALUE=""
SIZE=32>
</TD>
</TR>
<TR>
<TD WIDTH=83>
<P><INPUT TYPE=button VALUE="Submit"
onclick="verify()">
</TD>
<TD>
<P><INPUT TYPE=reset VALUE="Clear Your
Information">
</TD>
</TR>
<TR>
<TD COLSPAN=2>
<P><TEXTAREA NAME=display ROWS=5 COLS=41
WRAP=virtual></TEXTAREA>
</TD>
</TR>
</TABLE>





</FORM>
</BODY>
</HTML>



























Weitere ähnliche Inhalte

Was ist angesagt? (20)

Web Design 101
Web Design 101Web Design 101
Web Design 101
 
Html
HtmlHtml
Html
 
CSS for Beginners
CSS for BeginnersCSS for Beginners
CSS for Beginners
 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
 
Java script
Java scriptJava script
Java script
 
Javascript
JavascriptJavascript
Javascript
 
Java script ppt
Java script pptJava script ppt
Java script ppt
 
Html / CSS Presentation
Html / CSS PresentationHtml / CSS Presentation
Html / CSS Presentation
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
HTML CSS & Javascript
HTML CSS & JavascriptHTML CSS & Javascript
HTML CSS & Javascript
 
Basic HTML
Basic HTMLBasic HTML
Basic HTML
 
Web development using javaScript, React js, Node js, HTML, CSS and SQL
Web development using javaScript, React js, Node js, HTML, CSS and SQLWeb development using javaScript, React js, Node js, HTML, CSS and SQL
Web development using javaScript, React js, Node js, HTML, CSS and SQL
 
Web development | Derin Dolen
Web development | Derin Dolen Web development | Derin Dolen
Web development | Derin Dolen
 
Span and Div tags in HTML
Span and Div tags in HTMLSpan and Div tags in HTML
Span and Div tags in HTML
 
Web Development
Web DevelopmentWeb Development
Web Development
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
 
Intro to HTML and CSS basics
Intro to HTML and CSS basicsIntro to HTML and CSS basics
Intro to HTML and CSS basics
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
 

Andere mochten auch

An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptFahim Abdullah
 
An Seo’s Intro to Web Dev, HTML, CSS and JavaScript
An Seo’s Intro to Web Dev, HTML, CSS and JavaScriptAn Seo’s Intro to Web Dev, HTML, CSS and JavaScript
An Seo’s Intro to Web Dev, HTML, CSS and JavaScriptTroyfawkes
 
HTML CSS JavaScript jQuery Training
HTML CSS JavaScript jQuery TrainingHTML CSS JavaScript jQuery Training
HTML CSS JavaScript jQuery Trainingubshreenath
 
An Intro to HTML5 and CSS3
An Intro to HTML5 and CSS3An Intro to HTML5 and CSS3
An Intro to HTML5 and CSS3Dhruva Krishnan
 
Crowdsourcing Presentation for Creative Company Conference
Crowdsourcing Presentation for Creative Company ConferenceCrowdsourcing Presentation for Creative Company Conference
Crowdsourcing Presentation for Creative Company ConferenceTrada
 
Animation powerpoint
Animation powerpointAnimation powerpoint
Animation powerpointAbbeyfield
 
my animation presentation (R&D module for university)
my animation presentation (R&D module for university)my animation presentation (R&D module for university)
my animation presentation (R&D module for university)MichaelCX25
 
Turing Church Online Workshop 2
Turing Church Online Workshop 2Turing Church Online Workshop 2
Turing Church Online Workshop 2Giulio Prisco
 
Presentation for Erasmusplus project LTSDU on PISA 2012 results in Italy
Presentation for Erasmusplus project LTSDU on PISA 2012 results in ItalyPresentation for Erasmusplus project LTSDU on PISA 2012 results in Italy
Presentation for Erasmusplus project LTSDU on PISA 2012 results in Italysisifo68
 
Power Point Presentation
Power Point PresentationPower Point Presentation
Power Point PresentationCharlCooper
 
Animation presentation
Animation presentationAnimation presentation
Animation presentationRounak Muchhal
 
Presentation logo contest for ltsdu
Presentation logo contest for ltsduPresentation logo contest for ltsdu
Presentation logo contest for ltsdusisifo68
 
Threads in PHP - Presentation
Threads in PHP - Presentation Threads in PHP - Presentation
Threads in PHP - Presentation appserver.io
 
Core Php Component Presentation
Core Php Component PresentationCore Php Component Presentation
Core Php Component PresentationJohn Coonen
 
PHP in one presentation
PHP in one presentationPHP in one presentation
PHP in one presentationMilad Rahimi
 

Andere mochten auch (20)

An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java Script
 
An Seo’s Intro to Web Dev, HTML, CSS and JavaScript
An Seo’s Intro to Web Dev, HTML, CSS and JavaScriptAn Seo’s Intro to Web Dev, HTML, CSS and JavaScript
An Seo’s Intro to Web Dev, HTML, CSS and JavaScript
 
HTML CSS JavaScript jQuery Training
HTML CSS JavaScript jQuery TrainingHTML CSS JavaScript jQuery Training
HTML CSS JavaScript jQuery Training
 
An Intro to HTML5 and CSS3
An Intro to HTML5 and CSS3An Intro to HTML5 and CSS3
An Intro to HTML5 and CSS3
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
Crowdsourcing Presentation for Creative Company Conference
Crowdsourcing Presentation for Creative Company ConferenceCrowdsourcing Presentation for Creative Company Conference
Crowdsourcing Presentation for Creative Company Conference
 
Animation powerpoint
Animation powerpointAnimation powerpoint
Animation powerpoint
 
Animation powerpoint
Animation powerpointAnimation powerpoint
Animation powerpoint
 
my animation presentation (R&D module for university)
my animation presentation (R&D module for university)my animation presentation (R&D module for university)
my animation presentation (R&D module for university)
 
Turing Church Online Workshop 2
Turing Church Online Workshop 2Turing Church Online Workshop 2
Turing Church Online Workshop 2
 
Presentation for Erasmusplus project LTSDU on PISA 2012 results in Italy
Presentation for Erasmusplus project LTSDU on PISA 2012 results in ItalyPresentation for Erasmusplus project LTSDU on PISA 2012 results in Italy
Presentation for Erasmusplus project LTSDU on PISA 2012 results in Italy
 
Taller heramientas multimedias
Taller heramientas multimediasTaller heramientas multimedias
Taller heramientas multimedias
 
Power Point Presentation
Power Point PresentationPower Point Presentation
Power Point Presentation
 
Presentation - Animation B2B
Presentation - Animation B2BPresentation - Animation B2B
Presentation - Animation B2B
 
Animation presentation
Animation presentationAnimation presentation
Animation presentation
 
Presentation logo contest for ltsdu
Presentation logo contest for ltsduPresentation logo contest for ltsdu
Presentation logo contest for ltsdu
 
Intro to HTML5
Intro to HTML5Intro to HTML5
Intro to HTML5
 
Threads in PHP - Presentation
Threads in PHP - Presentation Threads in PHP - Presentation
Threads in PHP - Presentation
 
Core Php Component Presentation
Core Php Component PresentationCore Php Component Presentation
Core Php Component Presentation
 
PHP in one presentation
PHP in one presentationPHP in one presentation
PHP in one presentation
 

Ähnlich wie Html JavaScript and CSS

CHAPTER 3 JS (1).pptx
CHAPTER 3  JS (1).pptxCHAPTER 3  JS (1).pptx
CHAPTER 3 JS (1).pptxachutachut
 
IT2255 Web Essentials - Unit III Client-Side Processing and Scripting
IT2255 Web Essentials - Unit III Client-Side Processing and ScriptingIT2255 Web Essentials - Unit III Client-Side Processing and Scripting
IT2255 Web Essentials - Unit III Client-Side Processing and Scriptingpkaviya
 
Iwt note(module 2)
Iwt note(module 2)Iwt note(module 2)
Iwt note(module 2)SANTOSH RATH
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]srikanthbkm
 
JavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationSoumen Santra
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript TutorialDHTMLExtreme
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascriptambuj pathak
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJSTroy Miles
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)Ajay Khatri
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTHSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTAAFREEN SHAIKH
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java scriptnanjil1984
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep DiveGabriel Walt
 
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 JavascriptArti Parab Academics
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalystdwm042
 
javascriptPresentation.pdf
javascriptPresentation.pdfjavascriptPresentation.pdf
javascriptPresentation.pdfwildcat9335
 

Ähnlich wie Html JavaScript and CSS (20)

CHAPTER 3 JS (1).pptx
CHAPTER 3  JS (1).pptxCHAPTER 3  JS (1).pptx
CHAPTER 3 JS (1).pptx
 
IT2255 Web Essentials - Unit III Client-Side Processing and Scripting
IT2255 Web Essentials - Unit III Client-Side Processing and ScriptingIT2255 Web Essentials - Unit III Client-Side Processing and Scripting
IT2255 Web Essentials - Unit III Client-Side Processing and Scripting
 
JavaScript_III.pptx
JavaScript_III.pptxJavaScript_III.pptx
JavaScript_III.pptx
 
Iwt note(module 2)
Iwt note(module 2)Iwt note(module 2)
Iwt note(module 2)
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]
 
JavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & Implementation
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
 
Wt unit 5
Wt unit 5Wt unit 5
Wt unit 5
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJS
 
Java script
Java scriptJava script
Java script
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
 
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPTHSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
HSC INFORMATION TECHNOLOGY CHAPTER 3 ADVANCED JAVASCRIPT
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep Dive
 
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
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
javascriptPresentation.pdf
javascriptPresentation.pdfjavascriptPresentation.pdf
javascriptPresentation.pdf
 
Lect35 javascript
Lect35 javascriptLect35 javascript
Lect35 javascript
 

Kürzlich hochgeladen

Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxPoojaSen20
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 

Kürzlich hochgeladen (20)

Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 

Html JavaScript and CSS

  • 2. History  What is the relationship between:  SGML  HTML  XHTML  CSS  JavaScript
  • 3. History  Markup  Annotations instructing how the document should appear in print  Word processors use different markup schemes  SGML IBM - Standard Generalized Markup Language Markup instructions stored with ASCII file  Any computer could render document  Lilly Example
  • 4. History  HTML  Tim Berners-Lee created HTML – subset of SGML  Not platform or application specific  Only server software needed to publish file s on the net  Structure versus content  Browser parses HTML file into a tree
  • 5. History  Sample HTML File  <FONT SIZE=14 FACE=Swing>  <B>Bryan Moore</B><BR>  </FONT>  <FONT SIZE=12 FACE=Textile>  1234 Sunset Ave. <BR>  Walla Walla, WA 12345 <BR>  (123)123.4567<BR>  </FONT> Web Applications and Real World Design - Knuckles
  • 6. History Browser parse tree Web Applications and Real World Design - Knuckles
  • 7. History  Problems with extracting data  Need to write a computer program to extract the names and addresses by selecting text strings following font tags  Content and structure of document become intertwined  Not the intention of SGML and original HTML  Cascading Style Sheets  Attempt to separate content and style
  • 8. History  CSS  Can alter the look of entire file with a simple coding change  Can keep styles in an external file  Increases the knowledge needed to code pages Initial rationale of HTML was to appeal to the masses
  • 9. History Parse tree using CSS Still need to reference Information based on “second string after BR” Information is not meaningful Web Applications and Real World Design - Knuckles
  • 10. History  Extensible Markup Language XML  Extensible- can create own tags  Complete separation of content and style Web Applications and Real World Design - Knuckles
  • 11. History  Releases  HTML 4.0 1997  XML 1.0 1998  XML and HTML need to better cooperate  XHTML 1.0 2000  XHTML  Contains elements and attributes of HTML  Elements must have closing tags  Lowercase  Attributes must have values  Attributes in single or double quotes  http://www.w3schools.com/xhtml/default.asp
  • 12. HTML Forms and JavaScript  Client Server Model  Client Side Processing  JavaScript downloaded from web page and processed by the client – typically form checking  JavaScript can interact directly with form data  Server Side processing  Information from a form sent to server for processing  PHP Perl C++  Server can interact directly with the form data
  • 13. HTML Forms and JavaScript  JavaScript  HTML files are text files  JavaScript is interpreted not compiled  Object oriented HTML forms are objects and can be manipulated via JavaScript Dynamic HTML – merger of JavaScript and HTML  Different implementations of DHTML by software companies
  • 14. What is JavaScript  Scripting language (object-oriented)  Lightweight programming language developed by Netscape  Interpreted, not compiled  Designed to be embedded in browsers        Ideal for adding interactivity to HTML pages Detect browser versions Work with info from user via HTML forms Create cookies Validate form data Read and write HTML elements Supported by all major browsers  Internet Explorer has JScript (started in IE3)  http://www.faqts.com/knowledge_base/view.phtml/aid/1380  It’s free, no license required
  • 15. What is JavaScript  Syntax is similar to Java, but it’s not Java per se  Usually JavaScript code is embedded within HTML code using the script tag:  Can have more than one pair of script tags in a page  Semicolons: C++ and JAVA require them but in JavaScript it’s optional
  • 16. What is JavaScript  HelloWorld example program…  <html>          <head><title>JavaScript HelloWorld! </title></head> <body> <script language="JavaScript"> document.write('Javascript says "Hello World!"') </script> </body> </html>  Let’s open it in the browser
  • 17. What is JavaScript  Javascript can be located in the head, body or external file  Head section Ensures script is loaded before trigger event  Body section Script executes when body loads  External Allows scripts to run on several pages  Examples: http://www.w3schools.com/js/js_whereto.asp
  • 18. What is JavaScript  JavaScript statements in head write to the beginning of the body section but don’t violate HTML code already there.  JavaScript statements in body write based on their location  JavaScript interpreted first then HTML interpreted second  Document.write writes to the HTML document not the web page
  • 19. What is JavaScript            <html> <head> <script language=“JavaScript”> document.write (“<b> This is first </b>); </script> </head> <body> Now where does this print on the web page???? <br /> <script language=“JavaScript”> document.write ( “This might be last?”) </script>   </body> </html>  Lets See what the answer is!
  • 20. What is JavaScript  Now, let JavaScript generate HTML for us…  <html>  <head><title>JavaScript HelloWorld!</title></head>  <body>  <script laguage="JavaScript">   document.write("<h2>Javascript-Generated output:</h2> <p>This paragraph generated by JavaScript</p>  <p>It can even insert an image</p>  <img src='../assigns/RayWeb/images/cathedral.jpg' />")   </script>  </body>  </html>  Let’s open it in the browser
  • 21. Identifier Etiquette  Identifier– The name of a variable (or function)  Starts with a letter, can contains digits & underscores  Case Sensitive!!  Should be meaningful to someone reading your code  Good: accountBalance, amountDue  Bad: bal, due,  Just plain wrong: 2bOrNotToBe, +var, total-value
  • 22. Variables  Must declare variables before they’re used in the program  Declare at the top of the program & terminate each statement with ‘;’  Intialize variables when appropriate  Local variables (declared within a function) destroyed after function exit.  Can only be accessed within the function  Example – Note Assignments  var candyBarPrice = 2.50;  var taxRate = .075;  var candyBarsPurchased;
  • 23. Assignment Operator  Assignment ‘looks like’ equal sign but does NOT behave like it  subTotal = subTotal + 1.50  subTotal ‘is assigned the value’ that is currently in subTotal plus the value of 1.50
  • 24. Expressions  An expression is a statement that describes a computation  Usually look like algebra formulas  total = subTotal * taxRate  Operators (+, -, *, /, etc.) have different levels of precedence, similar to algebra  Don’t rely on it! For clarity, use parentheses  w3Schools operator reference page
  • 25. Conditional Statements--if if (some boolean expression is true){ execute the statements within the curly braces, otherwise skip to the first statement after the closing brace } Resume execution here in either case
  • 26. Conditional Statements– if/else if (some boolean expression is true){ execute these statements, otherwise skip to ‘else’ clause } else { execute these statements if boolean expression is false } Resume execution here in either case
  • 27. Conditional Test Program  Diagnostic messages indicate flow of control 1. 2. 3. 4. var variable1 = 1; var variable2 = 2; 1. 2. if(variable1 > variable2){ if(variable1 >= 0){ document.write(“<p> 1 is greater than 0 </p>"); 5. } 6. document.write(“<p>Resuming execution after 'if' 7. statement</p>"); 8. 3. 4. 5. 6. • document.write(“<p>1 is greater than 2</p>"); } else { document.write(“<p>2 is greater than 1</p>"); } document.write("Resuming execution after
  • 28. Strings  Strings are sequences of keyboard characters enclosed in quotes  “Hello World” or ‘Hello World’  Variables can hold strings  var greeting = “Hello World”  String can be empty, i.e., contain no characters  var myAnswer = “”  Use ‘’ (escape symbol) to ‘type’ prohibited characters  b for backspace, n for newline, t for tab, ” for double quote
  • 29. JavaScript Functions – Basic Principles  Abstraction  Experience has taught us that much code is duplicated throughout program  Functions let us write the functionality once, then reuse it
  • 30. JavaScript Functions – Basic Principles  Encapsulation  Functions encapsulate a specific capability or feature  Function name allows us to access a function in our program  Parameterization  We can customize the function’s result by passing in different values each time we use it  Must use functions to write serious software!
  • 31. JavaScript Functions – Basic Principles  Reasons to use functions  Ease of communication  Problem simplification  Easier construction  Code readability  Reusability  Maintainability  In JS, functions are the primary encapsulation mechanism
  • 32. JavaScript Functions – Syntax  JS function syntax function myFunctionName (list of parameters) { ….JS code here… }
  • 33. JavaScript Functions -- Issues  Key issues about using functions  Naming functions  Passing in parameters  Using local variables within functions  How to call (i.e., invoke) functions  How to handle a function’s return value  Where to put JS functions in your webpage
  • 34. JavaScript Functions – Naming  Function names  Name describes what function does  Name is an identifier, so follow JS identifier syntax rules & course coding standards  Example, findMaxValue(‘put some parameters here’)
  • 35. JavaScript Functions -- Parameters  Passing parameters to the function  Parameters provide functions with input  Implicitly declared variables that can be accessed by code within function body  You provide actual input values when you call the function  Parameters are named variables separated by commas  Example, function findMaxValue(num1, num2, num3)
  • 36. JavaScript Functions – Where to put?  Put functions within <script>….</script> tags within the <head> section of the web page <head> <script language=“JavaScript”> declare functions here…. </script> </head>
  • 37. JavaScript Functions – Local Variables  If needed, you can declare local variables within a function  local variable is visible only within the function body after it’s declared  Commonly used to store results of an intermediate calculation
  • 38. JavaScript Functions – Local Variables function findMaxValue(num1, num2,num3) { var tempMax; //local var if (num1 >= num2) { tempMax = num1; } else { tempMax = num2; } if(num3 >= tempMax) { tempMax = num3; } return tempMax; } //end function
  • 39. JavaScript Functions -- Calling  To call a function from your program, add a statement that contains the function name with values for the parameters the function requires  Example…somewhere in the <body>…., var x = 1, y = 4, z = 2; findMaxValue(x, y, z);  What value does the function return?  What happens with the result?
  • 40. JavaScript Functions -- Return  Return keyword tells function to return some value and exit immediately  Function can have multiple return statements but only 1 can be executed in any given function call  Normally used to return the final result of a calculation to the calling program  For an example, see findMaxValue function
  • 41. JavaScript Functions -- Return  Good Example  Uses var maxNumber in calling program  Function’s return value is assigned to maxNumber  Display of maxNumber has correct value for inputs  Code snippet  var x = 1, y = 4, z = 2; var maxNumber = findMaxNumber(x, y, z); document.write(“The maximum is: “ + maxNumber);
  • 42. JavaScript Functions – Parameter Sequence  1. 2. 3. 4. 5. 6. 7. 1. 2. When calling functions, must enter parameters in same order as specified in function argument list. function calculateDensity(height, width, depth, mass){ var volume = height * width * depth; var density = mass / volume; return density; } ………………………………………………. var hth = 2, wth = 3, dth = 4, mass = 10; var result = calculateDensity(2, 10, 3, 4); //returns .07 but correct answer is .42!!!
  • 43. JavaScript Functions – Global Variables  Global variables are those declared outside of functions  Global variables are ‘visible’ from anywhere in the program, including inside functions var globalHello = “Hello!”; function writeHello() { document.write(globalHello); } // outputs “Hello!” Example program
  • 44. JavaScript Functions – Testing  Test each function thoroughly before proceeding with next programming task  Using multiple sets of inputs, be sure to test all possible outcomes  For each test, be sure calling program is properly handling return values
  • 45. JavaScript Functions – Debugging  Use diagnostic output statements to trace program execution  Good places for diagnostic outputs  Just before entering function  Immediately upon entering function  Before/In/After complex logic or computation  Just before function return statement  Immediately after function returns to calling program
  • 46. JavaScript Functions  Built-In Functions  Prompt  Alert  Confirm  http://www.w3schools.com/js/js_popup.asp
  • 47. JavaScript and HTML Forms  JavaScript Objects  Var truck = new Object();  Expression on right is a constructor  Properties truck.color=“white” document.write(color);  Primitives  In JavaScript variable primitive types are number, string and Boolean
  • 48. JavaScript and HTML Forms  Object Model for the Browser Window  Compound object structure is created when a web page loads into a browser Hierarchy  Window is an object, the HTML document is an object and its elements are objects  These objects have primitives associated with them
  • 49. JavaScript and HTML Forms  window [closed, location] history [length] document [bgColor, fgColor, URL, lastmodified,linkColor, vlinkColor]     images [properties] links [properties] frames [properties] forms [properties]
  • 50. JavaScript and HTML Forms  Window object is parent of structure  window.closed is primitive that is Boolean  window.location primitive contains string of the URL of the HTML file  window.document object is primary focus  When web page is loaded the HTML elements assign values to most of these window.document primitives  Often the word window is excluded as in document.write but need it if referring to multiple open windows  Properties can also be objects
  • 51. JavaScript and HTML Forms                   <HTML> <HEAD> <TITLE>Document Properties</TITLE> <SCRIPT LANGUAGE=JavaScript><!-document.write(closed); document.write("<BR>"+ document.bgColor); document.write("<BR>"+document.fgColor); document.write("<BR>"+document.lastModified); //--></SCRIPT> </HEAD> <BODY TEXT="#0000FF" BGCOLOR="#FFFFCC"> <P>Blue text on a yellow background.<BR> <SCRIPT LANGUAGE=JavaScript><!-document.write("<BR>"+ document.bgColor); document.write("<BR>"+document.fgColor); //--></SCRIPT> </BODY> </HTML> Interactive Programming on the Internet Knuckles
  • 52. JavaScript and HTML Forms  false #ffffff #000000 01/10/2001 17:18:30 Blue text on a yellow background. #ffffcc #0000ff Interactive Programming on the Internet, Knuckles
  • 53. JavaScript and HTML Forms  Methods  Behavior associated with an object  Essentially functions that perform an action  Some are built in and others user made  Built-In Methods of the window object  Confirm  Alert  Prompt
  • 54. JavaScript and HTML Forms  User Events  An event occurs when a user makes a change to a form element Ex. Click a button, mouseover an image  Detection of an event done by event handlers  Event handler is an attribute of the HTML button  <form> <input type=button value=“please click” onclick=“function name()”>  </form>
  • 55. JavaScript and HTML Forms <HTML> <HEAD> <SCRIPT LANGUAGE=JavaScript><!-function changecolor(){ document.bgColor="#ff0000"; } //--></SCRIPT> </HEAD> <BODY> <P><FORM > <P><INPUT TYPE=button VALUE="Click Me" onclick="changecolor()">  </FORM>  </BODY>  </HTML>            Interactive Programming on the Internet ,Knuckles
  • 56. JavaScript and HTML Forms  Form Object  Window.document.form  A form is a property of the document but is also an object  Form elements are properties of a form and are also objects  Access to form’s properties is done through the NAME attribute of the FORM tag  Access to the properties of the form elements is done through the NAME attributes of the particular form element
  • 57. JavaScript and HTML Forms Interactive Programming on the Internet ,Knuckles
  • 58. JavaScript and HTML Forms                          <HTML> <HEAD> <SCRIPT LANGUAGE=JavaScript><!-function plus(){ var n1; var n2; n1=document.addmult.num1.value; n2=document.addmult.num2.value; n1=parseFloat(n1); n2=parseFloat(n2); document.addmult.result.value=n1+n2; } function times(){ var n1; var n2; n1=document.addmult.num1.value; n2=document.addmult.num2.value; n1=parseFloat(n1); n2=parseFloat(n2); document.addmult.result.value=n1*n2; } Interactive Programming on the Internet ,Knuckles               //--></SCRIPT> </HEAD> <BODY BGCOLOR="#FFFFCC"> <P><FORM name=addmult> <P>Enter a number in each field: <INPUT TYPE=text NAME=num1 VALUE="" SIZE=5> <INPUT TYPE=text NAME=num2 VALUE="" SIZE=5><BR> <INPUT TYPE=button VALUE="+" onclick="plus()"> <INPUT TYPE=button VALUE="*" onclick="times()"><BR> <INPUT TYPE=reset VALUE="Reset Form"><BR> <TEXTAREA NAME=result ROWS=3 COLS=27 WRAP=virtual></TEXTAREA> </FORM> </BODY> </HTML>
  • 59. JavaScript and HTML Forms Form for submitting info for server side processing Interactive Programming on the Internet ,Knuckles
  • 60. JavaScript and HTML Forms                           <HTML> <HEAD> <SCRIPT LANGUAGE=JavaScript><!-function verify(){ with(document.infoform){ if((fullname.value=="")||(address.value=="")|| (email.value=="")){ alert("You have left one or more fields blank. Please supply the necessary information, and resubmit the form."); } else { display.value="The following information has been added to our guestbook:r"+fullname.value+"r"+ address.value +"r" +email.value; } } } //--></SCRIPT> </HEAD> <BODY BGCOLOR="#FFFFCC"> <P><FORM name=infoform> <P><TABLE BORDER=0> <TR> <TD WIDTH=83> <P>Name: </TD> <TD> <P><INPUT TYPE=text NAME=fullname VALUE="" SIZE=32> </TD> </TR>   <TR>    <TD WIDTH=83> <P>Address: </TD> <TD> <P><INPUT TYPE=text NAME=address VALUE="" SIZE=32> </TD> </TR> <TR> <TD WIDTH=83> <P>E-mail: </TD> <TD> <P><INPUT TYPE=text NAME=email VALUE="" SIZE=32> </TD> </TR> <TR> <TD WIDTH=83> <P><INPUT TYPE=button VALUE="Submit" onclick="verify()"> </TD> <TD> <P><INPUT TYPE=reset VALUE="Clear Your Information"> </TD> </TR> <TR> <TD COLSPAN=2> <P><TEXTAREA NAME=display ROWS=5 COLS=41 WRAP=virtual></TEXTAREA> </TD> </TR> </TABLE>    </FORM> </BODY> </HTML>                         

Hinweis der Redaktion

  1. To insert a JavaScript into an HTML page, we use the &lt;script&gt; tag (also use the type attribute to define the scripting language). So, the &lt;script type=&quot;text/javascript&quot;&gt; and &lt;/script&gt; tells where the JavaScript starts and ends: By entering the document.write command between the &lt;script type=&quot;text/javascript&quot;&gt; and &lt;/script&gt; tags, the browser will recognize it as a JavaScript command and execute the code line. In this case the browser will write Hello World! to the page: