HTML5, CSS3, and JavaScript Fourth Edition

(Ben Green) #1

CHAPTER 38. CH35 CONTENT, PRESENTATION, ACTION 304


38.7 Action


In olden days, webpages were static. You clicked on a link and got a whole
new page. The burden was on the webserver to control everything. To
change the webpage, we have the server revise it and send it back to us.


The modern approach is to move that control more and more into the web-
page itself.


A good example is form validation. You might key in a credit card number
and try to submit your form, but the webpage may do a preliminary check
on the credit card number to make sure it is valid, or at least not clearly
invalid.


Credit card numbers include something called a check digit, which generally
comes last. That digit can be totally predicted by the digits that come
before it. If you change the last digit, you don’t get a different credit card.
Instead you get an invalid number, one that can never be correct for any
credit card.


By checking for a correct check digit, the webpage can save the server some
work. Most errors result from one digit being changed, or from two digits
being swapped. The check digit catches 100% of those kinds of errors.


This form validation is typically done using JavaScript.


We will talk about JavaScript lightly. It is more advanced than we really
want to get into deeply. That is why we will just talk about it lightly.
(Whole books have been written about JavaScript.)


AJAX: Even more powerful than simple JavaScript is something called
AJAX, which we discuss briefly in section 17.7.4 (page 183). AJAX uses
JavaScript to update just a part of a webpage with new content from the
web.

Free download pdf