By Reaz Hoque
An Online Order Form in JavaScript
Many Web designers realize that form-based Web pages give them too much to worry about. Forms can be used for purposes as simple as submitting visitor feedback or displaying a catalog or product directory. But no matter how simple or difficult the form is, the developer must still learn CGI, have access to a CGI-bin directory, ensure that the CGI script runs fast, and so on. Enter JavaScript, the client-side scripting language that provides a viable alternative for handling HTML forms.
JavaScript lets you submit forms faster than CGI, and can also save a lot of programming time and money. This article presents a script that selects computer parts from a list and calculates their prices. You can then fill in the necessary shipping information to order the selected computer components. Once sent, the order information will be received by a configurable email account from which the order can be processed.
Start with HTML
First, you'll need to create the HTML page that will interact with JavaScript. The entire page is basically a form defined using the HTML code in
Figure 1(a). Use the POST method for the form, and, because the information will be sent via email, set the form action to the email address of the person who will be processing the order. Be sure to set the encryption type to "text/plain" (ENCTYPE="text/plain"), or your email data will be encrypted, which will make it exceedingly difficult to understand.