Page 34 - LoudOffice_Guide-to-HTML_Part-II_Advanced.PDF
P. 34

< / s c r i p t >
                       < / b o d y >
                       < / h t m l >




               Validating Form Data With JavaScript
               One of the most commonly used applications for JavaScript on the Web is for form
               validation.  Form validation allows a web programmer to check information entered onto a
               form before it is submitted to the server.    The benefit to you as a webmaster is that by
               validating the form on the browser (client), you will be saving valuable processing resources
               on the web server.

               JavaScript form validation occurs on a specific event – when the document is ‘submitted’
               (when the submit button is pressed).      A JavaScript function is called on the submission
               action that ‘looks’ at the form and makes sure that information has been correctly entered
               into each field.  JavaScript can actually look at the form and each field so long as each
               element is named.  For instance if you have a field named “email_address” in a form named
               “feedback_form”,     JavaScript    would     be    able   to    reference    that   field   as
               d o c u m e n t . f e e d b a c k _ f o r m . e m a i l _ a d d r e s s .   It is then possible to determine whether
               information was submitted to the form and if so, if it is ‘correct’.

















































               LoudOffice.com Guide to HTML – Part II                                               Page 34
   29   30   31   32   33   34   35   36   37   38   39