This document provides an overview of JavaScript and DOM for a lecture on internet programming. It outlines the objectives of understanding basic JavaScript concepts and the client-server model. The agenda covers what JavaScript is and why it is useful, where JavaScript code can be located, and how to process user input with DOM. It also gives examples of arithmetic operators in JavaScript and a simple cashier application example.
2. Objectives
By the end of this lecture, students will be able to:
âș grasp the basic concepts of javascript and DOM
âș describe the Client-Server Model
âș differentiate between client-side scripting and
server-side scripting
âș develop a simple javascript that involves simple
arithmetic operations
2 of 15
3. Agenda
âș Javascript is NOT Java programming language
âș What is javascript?
âș Why learn javascript?
âș Client- Server Model
âș Where Javascript Can Be Located?
âș Processing User Input, DOM.
âș e.g @the cashier
âș References
3 of 15
4. Javascript is NOT Java
Java
âș developed by SUN
âș a powerful OO
programming language .
âș involved compiling java
code into executable
applications.
âș Java programs created
for use in a web page is
called APPLET.
javascript
âș Designed by Netscape
âș A powerful OO scripting
language
âș Need an interpreter
(Browser dependent)
âș To enhance the
interactivity of web
pages
4 of 15
5. What is Javascript?
âș JavaScript is a scripting languages (lightweight)
âș It is usually embedded directly into an HTML doc
âș Is an interpreted language â browser dependent
âș JavaScript provides a programming language that
allows pages to escape from being static marked-
up information. â dynamic & interactive
âș JavaScript is used in millions of Web pages to add
functionality, validate forms, detect browsers,
and much more. It is free!!!
âș Pages that think.
5 of 15
6. Why learn JavaScript?
âș JavaScript gives HTML designers a
programming tool - HTML authors are normally
not programmers, but JavaScript is a scripting
language with a very simple syntax! Almost
anyone can put small "snippets" of code into their
HTML pages
âș JavaScript can put dynamic text into an HTML
page - A JavaScript statement like this:
document.write("<h1>" + name + "</h1>") can
write a variable text into an HTML page
6 of 15
7. âŠWhy learn JavaScript?
âș JavaScript can react to events - A JavaScript can
be set to execute when something happens, like
when a page has finished loading or when a user
clicks on an HTML element
âș JavaScript can read and write HTML elements -
A JavaScript can read and change the content of
an HTML element
âș JavaScript can be used to validate data - A
JavaScript can be used to validate form data
before it is submitted to a server.
7 of 15
8. âŠWhy learn JavaScript?
âș JavaScript can be used to detect the visitor's
browser - A JavaScript can be used to detect the
visitor's browser, and - depending on the browser
- load another page specifically designed for that
browser
âș JavaScript can be used to create cookies - A
JavaScript can be used to store and retrieve
information on the visitor's computer
8 of 15
11. Where Javascript Can Be Located?
1. In the <body> section
ï§ eg_js_01_body.html
2. In the <head> section
ï§ eg_js_01_head.html
3. As an external file
ï§ eg_js_01_external.html
11 of 15
12. Processing User Input
âș Javascript uses XHTML Documents Object Model
(DOM) to process user input
âș View a list of available objects
http://www.w3schools.com/js/js_obj_htmldom.asp
âș javascript event reference
http://www.w3schools.com/jsref/jsref_events.asp
âș Click eg_js_02.html to view an example of DOM
and onchange() event.
âș eg_js_01.html example of event, onclick().
12 of 15
13. Arithmetic Operator
Operator Description Example Result
+ Addition z = 5 + 4; z = 9
- Subtraction z = 5 â 4; z = 1
* Multiplication z = 5 * 4; z = 20
/ Division z = 5 / 4; z = 1.25
% Modulus
(remainder)
z = 5 % 4; z = 1
++ Increment z = 1;
y = ++z;
y = 2
-- Decrement z = 1;
y = --z;
y = 0
13 of 15