Basic Form Validation : Form Validation « Form « HTML / CSS

HTML / CSS » Form » Form Validation 
Basic Form Validation

<HTML>
<HEAD>
<TITLE>Basic Form Validation</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function validate () 
{
    if (document.forms.order.CustName.value == "") {
        alert("Please enter your name.")
        return;
    }

    if (document.forms.order.CustID.value == "") {
        alert("Please enter your Customer ID.")
        return;
    }

    if (document.forms.order.Qty.value <= 0) {
        alert("Please enter a positive number of gadgets.")
        return;
    }

    document.forms.order.submit();
    alert ("Your order has been submitted");
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<H1 ALIGN="CENTER">Gadget Order Form</H1>
<HR>
<FORM NAME="order" METHOD="POST" ACTION="mailto:[email protected]">
<B>Customer Name: </B>
<INPUT TYPE="TEXT"
  NAME="CustName"
  SIZE="25"
  MAXLENGTH="35">
<BR><BR>

<B>Customer ID:</B>
<INPUT TYPE="PASSWORD"
  NAME="CustID"
  SIZE="8"
  MAXLENGTH="9">

<BR><BR>
<B>Quantity of Gadgets:</B>
<INPUT TYPE="TEXT"
  NAME="Qty"
  SIZE="2"
  MAXLENGTH="2">

<HR>
<INPUT TYPE="BUTTON"
  VALUE="Order"
  onclick="validate()">
<INPUT TYPE="RESET" VALUE="Reset">

</FORM>
</BODY>
</HTML>




           
       
Related examples in the same category
1.For more please visit Javascript section on the left side
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.