250
Chapter 13 Objects and the Internet
The reason why this example is so interesting is because it’s a perfect example of the inter-
face/implementation paradigm stressed throughout this book. In this case, the client is re-
questing a service from the server.The software system provides an interface through
which the client can literally send messages and request specific services from the server.
In the example relating to the Age field in the HTML document in Figure 13.2, sup-
pose a user named Mary wants to update her age in the database.After bringing up the
web page, the user enters the appropriate information on the form (including her age in
the Age field) and then clicks on the Register button. In the simplest scenario, the infor-
mation in the form is sent to the server, which then processes the information and updates
the database.
How is the information entered in the Date field verified? If no validation is done, the
software on the server accesses the Age field in Mary’s record and makes the update. If the
age that Mary enters is incorrect, the inappropriate age is entered in the database.
If the validation is done on the server, the software on the server checks to make sure
that the Age value falls into appropriate ranges. It is also possible that the database itself
does some checking to ensure that the age is within proper limits.
However, there is one major limitation to server-side validation—the information must
be sent to the server.This might seem counter-intuitive, but you can ask this simple ques-
tion:Why validate something on the server that can be validated on the client?
There are several points that address this question:
n
Sending things to the server takes more time.
n
Sending things to the server increases network traffic.
n
Sending things to the server takes up server resources.
n
Sending things to the server increases the potential for error.
For these reasons, as well as other possible issues, our goal is to do as much of the valida-
tion on the client as possible.This is where the scripting languages come into play.
A JavaScript Validation Example
JavaScript, as are most scripting languages, is considered to be object-based. Just like C++,
you can write JavaScript applications that do not comply with object-oriented criteria.
However, JavaScript does provide object-oriented capabilities.This is what makes scripting
languages, like JavaScript and ASP .NET, very important in the object-oriented market.
You can use objects in a JavaScript application to enhance the capabilities of your web
page. In some ways, you can think of these scripting languages as bridges between tradi-
tional programming paradigms and object-oriented models. I feel it is important to un-
derstand you can incorporate objects into your web applications, even if you aren’t using
pure object-oriented technologies.
To understand the power of the scripting languages, we must first understand the limi-
tations of HTML. HTML is a markup language that provides functionality, not inherent
programming capabilities. For example, there is no way in HTML to program an
IF state-