GEHC JS Class 3 About Forms ----------- Forms are an essential part of any interactive site - they allow you to give the user a chance to fill in data specific to them, whether it is a name, address, credit card number, color preference, or email address. In addition, we can use forms to build pages that gather data on one page and pass it along to many other pages. We will leverage this ability in the very last week of class, after we learn about Perl. In the meantime, JavaScript goes hand in hand with almost every form that I build on the web. There are lots of reasons why, which we'll touch on today. Forms and data validation ------------------------- Validation of data placed in forms by users is critical. It must be done before the server tries to store the data, or else the data will be useless. We can validate data on the server, but that's our last line of defense and the one that is the least useful to users. What users want is instant feedback about what they have done wrong. Using JavaScript, we can validate user input before it ever leaves the client, providing instant feedback to the user, and sparing our server a hit for simple data validation. Is it blank? ------------ One of the first tests we will want to do is find out if a data field is blank or not. Very often, there are required fields in a form, and we will make sure we are able to test those fields to see if they are blank. ** JS3-1 - a simple text box, with a first attempt at blankness testing. This testing is broken, because it is too simple. If the user types nothing in the box and presses Submit, it will tell them the box is empty. If they type anything else in the box, it will say it is not empty... but if they type in spaces, then that passes the != "" test, but is obviously wrong. We need a function to test data for blankness. *TIME OUT* Let's take a few moments to look at the HTML and the corresponding JS in this example. In the HTML, we have a form: