john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

html form validation

//if the onsubmit value is returned false then the form will NOT submit

<FORM ACTION="website.php"     NAME="testform"      onSubmit="return TestDataCheck()">

</form>




<SCRIPT TYPE="text/javascript">


function TestDataCheck()
{

    if ( (qtytested >= 1) && (qtypassed >= 0) && (qtytested >= qtypassed))
           returnval = true;
    else
       {
           alert("must enter the quantity tested and that amount or fewer for quantity passed");
           returnval = false;
       }


</SCRIPT>


<form action="post.php" method="post" name="myForm" onsubmit="return validateMyForm()">


<script type="text/javascript" language="javascript">

function validateMyForm()
{
    if (document.myForm.first_name.value == '') {
        alert('Please enter your first name');
        document.myForm.first_name.focus();
        return false;
    }

  • « html note self submit php
  • html form replace button with image and label for »

Published

Feb 6, 2010

Category

web

~73 words

Tags

  • form 20
  • html 23
  • validation 8
  • web 56