WEB PROGRAMMING UNIT-II NOTES
UNIT
– II
Overview
:
Unit-II
demonstrates on client side validations using JavaScript. It focuses on how to
handle events, exceptions, etc. This unit also focuses on DHTML concepts.
CONTENTS:
1)
JavaScript concepts
2)
Objects in java scripts
3)
DHTML with JavaScript
JavaScript (also
called JScript) is a scripting language with the primary aim of giving life to our web pages.It is very powerful,
flexible, and easy to learn.
Features
Ø Imperative and
structured
Ø Dynamic
o
dynamic typing
o
object based
o
run-time evaluation
Ø Functional
o
first-class functions
o
nested functions
o
closures
Ø Prototype-based
Ø Miscellaneous
Ø Vendor-specific
extensions
There are
three ways by which we can place Javascript for use in a web page.
1. Inside the head section.
2. Within the body section.
3. In an external file.
The HTML <script> tag is used
to insert a Java Script into an HTML page.
Events
|
By using JavaScript, we
have the ability to create dynamic web pages. Events are actions that can be
detected by Java Script.
Every element on a dynamic
or static web page has certain events which can trigger Java Script
functions. For example, we can use the onClick event of a button element to
indicate that a function will run when a user clicks on that button. We
define the events in the HTML tags.
Examples of events:
A mouse click
A web page or an image loading Mousing over a hot spot on the web page
Selecting an input box in an HTML form Submitting an HTML form
A keystroke
Events are
normally used in combination with functions, and the function can not be
executed before the event occurs.
|
JavaScript - Catching Errors
There are two ways of catching errors in a Webpage
Try...Catch
Statement
The try...catch
statement allows you to test a block of code for errors. The try block contains
the code to be run, and the catch block contains the code to be executed if an
error occurs.
try
{
//Run some
code here
}
catch(err)
{
//Handle
errors here
}
The onerror
Event
|
The onerror
event can be explained soon, but first you will learn how to use the throw
statements to create an exception. The throw statements can be used together
with the try...catch statement.
|
The Date object
The Date class is used to store and retrieve dates in
JavaScript.
Array
The Array object is used to holding a set of data or values in a
single variable name. var urArray=new Array()
DOM (document
object model)
A DOM (document
object model) is an application programming interface (API) for representing a
document (such as an HTML document) and accessing and manipulating the various
elements (such as HTML tags and strings of text) that make up that document.
Java Script-enabled web browsers have always defined a document object model; a
web-browser DOM may specify, for example: that the forms in an HTML document
are accessible through the forms[] array of the Document object.
form validation
Form validation
is the process of checking that a form has been filled in correctly or not
before it is processed.
There are two methods
1: Client-Side
validation
In Java Script
Client-side form validation is an important part of a web site where data needs
to be collected from the user. Users are innately ignorant, and will mess up
data entry in a web form if given the chance. It is the job of the web
programmer, then, to make sure his pages which use forms include client-side
form validation using JavaScript.
2: Server-side
validation
In Java Script
the server also benefits from client-side validation since it saves a number of
round-trips between the visitor and the server owing to typos and easily
spotted mistakes. This advantage does not alleviate the neccessity of doing
server-side validation.
Comments
Post a Comment