Q:

Javascript Program to implement Contact Form Validation

0

Program to implement Contact Form Validation.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<html>
<head>

<script>
function validation()
{
var name=document.BasicForm.Name;
        
if( name.value == "" )
{
  alert( "Please Enter the name!" );
  name.focus() ;
  return false;
}
        
var email = document.BasicForm.EMail.value;
atpos = email.indexOf("@");
dotpos = email.lastIndexOf(".");
         
if (atpos < 1 || ( dotpos - atpos < 2 )) 
{
alert("Please enter correct email ID")
document.BasicForm.EMail.focus() ;
return false;
}
      
var password=document.BasicForm.Password;
if (password.value == "" || isNaN( password.value ))                       
   {
        window.alert("Please enter your password");
        password.focus();
        return flase;
    }

var country=document.BasicForm.Country;
if(country.value == "Default")
   {
        alert('Select any country from the list');
        country.focus();
        return false;
   }
    }
</script>
</head>
   
<body>
<h1> Contact Form</h1>
<form  name="BasicForm" onsubmit="return(validation());">
<p>Name: <input type="text"  name="Name"> </p><br>      
            
<p>E-mail:  <input type="text"  name="EMail">  </p><br>
            
<p>Password: <input type="text"  name="Password"> </p><br>
            
<p>Country:   
<select name="Country">
 <option selected="" value="Default">(Please select a country)</option>
                     <option>India</option>
                     <option>China</option>
                     <option>USA</option>
                     <option>Australia</option>
</select>
</p>
            
<input type="submit" value="Submit" name="Submit">  
            
         
</form>
      
</body>
</html>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now