HTML and CSS Reference
In-Depth Information
You can add useful behavior to a web page with just a little bit of JavaScript added to the
onclick attribute of a link or to a script tag at the top of an HTML document. And as
you'll learn in Lesson 16, “Using JavaScript Libraries,” JavaScript libraries make it easy
to add functionality to web pages using just a few lines of code. The point is, don't be
intimidated by JavaScript. You can start accomplishing things almost immediately.
Increasing Server Efficiency
One of the main advantages of JavaScript is that it can provide user feedback instantly.
Instead of requiring users to submit a form to see if their input was valid, you can let
them know in real time. Not only can this improve user experience, but it can also make
life easier for your server, by preventing unnecessary form processing. In other cases,
you can use advanced JavaScript applications along with programs on the server to
update parts of a page rather than reloading the entire thing. Suppose that you've created
a form that people use to enter their billing details into your online ordering system.
When this form is submitted, your server-side script first needs to validate the informa-
tion provided and make sure that all the appropriate fields have been filled out correctly.
It needs to check that a name and address have been entered, that a billing method has
been selected, that credit card details have been submitted—and the list goes on.
But what happens when the script on the server discovers that some information is miss-
ing? You need to alert the visitors that there are problems with the submission and ask
them to edit the details and resubmit the completed form. This process involves sending
the form back to the browser, having the visitor resubmit it with the right information,
revalidating it, and repeating the process until everything is correct. This process can be
resource-intensive on the server side and could potentially discourage users from com-
pleting their order.
By adding validation and checking procedures to the web browser with JavaScript, you
can reduce the number of transactions because many errors will be caught before forms
are ever submitted to the server. And because the web server doesn't need to perform as
many validations of its own, fewer server hardware and processor resources are required
to process form submissions. The side benefit is that users will find your application
more responsive because the trip back to the server isn't required for validation.
Integration with the Browser
JavaScript enables you to manipulate objects on the page such as links, images, and form
elements. You can also use JavaScript to control the browser itself by changing the size
of the browser window, moving the browser window around the screen, and activating or
deactivating elements of the interface. Technologies like Flash can provide an interactive
interface, but they are not integrated into the browser in the same way that JavaScript is.
14
 
Search WWH ::




Custom Search