">
Domain Registration : Discount Domain Pricing : Website and Domain Hosting : Frontpage 2000 Hosting : Website Development and Promotion : Secure E-Commerce : Shopping Cart Software : Linux and Windows NT : Graphic Design : Free Email Services : Fast Servers : Low Cost!


RESOURCES





One of the most common and easy uses for JavaScript is form validation. Adding form validation is as simple as including an "onsubmit" event in the FORM tag, and having that call a function which validates the form fields before they are submitted. This saves the trouble of programming error-checking features into your CGI where the form is posted.


Below is an example of a simple form with a JavaScript form validation function. The script verifies that text has been entered into the form box. The form mails the webmaster the text entered by the user. You may copy this code to add a working form to your site, but it is not advisable to use a "mailto:" in the ACTION if you have access to CGI script, as the "mailto:" in the ACTION makes use of the browser's mail client and is a security issue.

    <! - - BEGIN FORM - ->
    <SCRIPT>

    function validateForm(form) { //This is the name of the function

    if (form.FIELD1.value == "") { //This checks to make sure the field is not empty
       alert("This field is empty."); //Informs user of empty field
       form.FIELD1.focus( ); //This focuses the cursor on the empty field
       return false; //This prevents the form from being submitted
       }
    // you may copy the above 5 lines for each form field you wish to validate
    // Replace the text "FIELD1" with the name you wish to call the field
    }
    </SCRIPT>



    <!- - Below you'll find the HTML that is the form itself to be placed between your BODY tags. You may replace the action with either a CGI or your own email address if you do not have access to a CGI script to collect form information. Also, replace the text "FIELD1" with the name you used in the script above.- ->

    <FORM METHOD="POST" ACTION="mailto:MAIL@YOURDOMAIN.COM" onSubmit="return validateForm(this)">
    <INPUT TYPE="TEXT" NAME="FIELD1" SIZE=10 MAXLENGTH=60 VALUE="">
    <INPUT TYPE="SUBMIT" NAME="ACTION" value="SUBMIT">
    </FORM>

    <!- - END FORM - ->












Copyright © 1995-2003 Sidetrips™ Internet Services, Inc. All rights reserved.

Reproduction in whole or in part in any form or medium without express
written permission of Sidetrips Internet Services, Inc. is prohibited.

sidetrips.com™, hostserver.com™, registera.com™, htmlshop.com™,
and associated domains are trademarks of Sidetrips™ Internet Service, Inc.

Privacy Policy | Acceptable Use Policy | Terms of Service