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

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

ValidationAssignmentAssistance

Page history last edited by Dr. Ron Eaglin 9 years, 6 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.