Here we come to the end of our brief four part introduction to simple Web forms. In the first two sections we talked a bit about what forms are and how they are used on the Web—and we also covered the process of planning your HTML form and choosing how to process it. In the third section we finally built a simply sample HTML form. It is for collecting the name, address, and sex of the user. We can now talk about adding code to the page that will verify that the form was filled out completely, and add an alert telling the user. If the form is complete is will submit to our imaginary application
Once that is done, any time you call a function or refer to the script anywhere in your form it will have automatically been accessible to the page from the “scrSample” script.
To add some processing to our initial practice script we can do the following things. First we will create a function that will verify that the user answered all the questions, and let them know with an alert which question they left blank. Before the form will successfully submit, it will need to be completed. This function will be called when the submit button is pressed by adding the following attribute to the form tag:
alert(“Please Enter a First Name”);
To take a look at a working copy of the entire practice form, visit a sample page on the web at: http://www.afinalword.com/dirSAMPLES/form-sample1.htm. If you bring the page up in your browser and select View Source from your browser’s tools you can follow the code. The practice form submits back to itself so that you can see the URL string submitted in the address bar of your browser.
We have now come to the end of the four part Functional Forms Series. It should have given you a taste of what forms can do on the Web. Remember that the basics are the key. Take a good look at the sites and books mentioned and start slow. Each time you learn something new you can add it to your practice form and script. Taking advantage of the numerous ways to collect information from your site visitors will help boost traffic to your site, or improve your skills as a developer.
John Adams Jr
John is a free-lance author and journalist born and raised in upstate New York. He is currently living and writing in Saint Augustine, Florida where the temperature is a bit warmer and the lifestyle more relaxed. The move has allowed John to broaden his range as a writer and he now lends his unique voice to everything from news and review articles in print and on the Web, to a broad range of eBooks and creative pieces. His expertise in Web Development and Design comes from a Masters Degree in Production Design from NYU and almost 10 years designing and programming sites and applications for various organizations. John’s writing work is beginning to attract attention from a wide variety of readers, in many countries, and he is exited to reach more people. See John’s Google+ Profile