HTML5, CSS3, and JavaScript Fourth Edition

(Ben Green) #1

CHAPTER 14. JAVASCRIPT AND AJAX 148


Variations:Show the artwork with various frames. Show the clothing with
various print patterns. Show the room with various wall colors. JavaScript
can make this instantaneous.


Filtering:Reduce and clear away clutter, showing the user just those pieces
of content that match their interests.


Validation: See whether the credit card number is legal. (Credit card
numbers include a check-digit to quickly find typing errors.)


See whether the email address they typed twice is the same both times.


See whether the password they typed twice is the same both times. And see
whether the password is strong or weak.


Calculators:Fill in a few blanks and see a result. Shipping costs? Mort-
gage or car payments?


Widgets:Paid advertisements, trending hashtags, latest comments, news-
feeds, weather, quote of the day, joke of the day: these use AJAX to update
your screen with new information.


But Wait!When users want to leave your webpage, JavaScript can put up
a message with a special offer. This can be really annoying, but it might be
just what your boss wants.


14.3 Try It: Changing Colors


Let’s get started. Add this HTML which includes a bit of JavaScript to any
webpage you care to mess up. This code will allow the user to change the
color of the text and the color of the background on a webpage, simply by
moving the mouse.


Text:
[Red]
[White]
[Blue]
[Black]
Background:
[Red]
[White]
[Blue]
[Black]

Free download pdf