| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

ValidationAssignmentAssistance

Page history last edited by Dr. Ron Eaglin 13 years, 2 months ago

Validation Assignment Assistance

 

Here is a little help with the validation assignment.For a video demonstrating how to use the code below Click Here.

 


 

Validation Example 1

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
 <head>
  <title>Example Validation</title>
  <meta http-equiv="content-Type" content="text/html; charset=UTF-8">        

  <script type = "text/javascript">

function validateForm()
{
var x=document.forms["exampleForm"]["name"].value
if (x==null || x=="")
  {
  alert("Name must be filled out");
  return false;
  }
}

   </script>

 </head>
 <body>
  <h1>Form Validation Example</h1>
  <br/>

  <form name="exampleForm"  onsubmit="return validateForm()" method="post">
   Name: <input type="text" name="name">
   <br/><br/>
   <input type="submit" value="Submit">
</form>

 </body>
</html>

 

Validation Example 2

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
 <head>
  <title>Example Validation</title>
  <meta http-equiv="content-Type" content="text/html; charset=UTF-8">        

  <script type = "text/javascript">

function validateNotBlank(fieldname,fieldvalue)
{

if (fieldvalue==null || fieldvalue=="")
  {
  alert(fieldname + " must be filled out");
  return false;
  }
  return true;
}

function validateName()
{
 var x=document.forms["exampleForm"]["name"].value;
 if (!validateNotBlank('Name ', x)) return false;
}


 </script>

 </head>
 <body>
  <h1>Form Validation Example</h1>
  <br/>

  <form name="exampleForm"  onsubmit="return validateName()" method="post">
   Name: <input type="text" name="name">
   <br/><br/>
   <input type="submit" value="Submit">
</form>

 </body>
</html>

 

Validation Example 3

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">
<html>
 <head>
  <title>Example Validation</title>
  <meta http-equiv="content-Type" content="text/html; charset=UTF-8">        

  <script type = "text/javascript">

function validateNotBlank(fieldname,fieldvalue)
{

if (fieldvalue==null || fieldvalue=="")
  {
  alert(fieldname + " must be filled out");
  return false;
  }
  return true;
}

function validateName(f)
{
 var x=f.fname.value;
 if (!validateNotBlank('Name ', x)) return false;
 return true;
}


function validateBirthday(f)
{
  var x=f.birthday.value;
  if (!validateNotBlank('Birthday ', x)) return false;
  var d1=new Date(x);
  var d2=new Date();
  var days=Math.round((d2-d1)/(1000*60*60*24));
  alert("You are  " + days + " days old");
  if (days<0) return false;  
  return true;
}

function displayGender(f)
{
  var x=f.gender.options[f.gender.selectedIndex].value;
  alert("You selected " + x);
}

function validate()
{
  var f=document.forms["exampleForm"];
 
  if(!validateName(f)) return false;
  if(!validateBirthday(f)) return false;
  displayGender(f);
}


 </script>

 </head>
 <body>
  <h1>Form Validation Example</h1>
  <br/>

  <form name="exampleForm"  onsubmit="return validate()" method="post">
   Name: <input type="text" name="fname">
   <br/><br/>
   Birthday (mm/dd/yyyy): <input type="text" name="birthday">
   <br/><br/>
   Gender: <select name="gender">
         <option value="M">male</option>
         <option value="F">female</option>
        </select>
   <br/><br/>
   <input type="submit" value="Submit">
</form>

 </body>
</html>

 

 

 

 

 

 

Comments (0)

You don't have permission to comment on this page.