Jump to content

JAVASCRIPT


sompal
 Share

Recommended Posts

<script type="text/javascript">

function checksName(form) 
{
  var eobj=document.getElementById('SnameError');
  var sName = form.sName.value;
  var oRE = /^[A-Z a-z]*$/;
  var error=false;
  eobj.innerHTML='';
  if (sName == '') {
   error='Error: Surname cannot be blank!';
   form.sName.focus();
  }
 
  else if (!oRE.test(sName))
{
   error="Incorrect format.";
  }
  
  if (error)
{
   form.sName.focus();
   eobj.innerHTML=error;
   return false;
  }

}

function validPhone(form)             
{
                       var eobj=document.getElementById('phonenoerror');
                       var valid = '0123456789';
                       var phone = form.phoneno.value;
                       var error=false;
                       var i=0;
                       var temp;
                       eobj.innerHTML='';
 if (phone == '') {
                  error='Error: Please enter phone number';
                                                                             }
   else if (!phone.length > 1 || phone.length < 😎 {
            error='please enter the 8 didgit only';}
     else{
   
       for (i=0; i < phone.length; i++){
           temp = '' + phone.substring(i, i + 1);
          if (valid.indexOf(temp) == -1) {
            error='Invalid characters, please enter only numbers';
                 }
               }
               }
         if (error){
             form.phoneno.focus();
              eobj.innerHTML=error;
               return false;}
               return true;}

function selectOnlyThis(id) {   
    for (var i = 3; i <= 9; i++)
    {
        document.getElementById("tick" + i).checked = false;
      
    }
       
   var ticked = document.getElementById(id).checked = true;
    var checkBox = document.getElementById("tick9");   
     
    }


function formValidation() 
 {
 var form = document.forms['form'];  
                                     /*  created array to store another function name to check their validation */
  var ary=[checksName,validPhone,selectOnlyThis];
 var rtn=true;
 var z0=0;
 for (var z0=0;z0<ary.length;z0++)
{
  if (!ary[z0](form))
  {
    rtn=false;
  }
 }
 return rtn;
}

<input type="checkbox" id="tick1"  onclick="selectOnlyThis(this.id)">
<label for="passport">Passport</label>
<span class="message" id="tickError"></span><br>

<div class="Objects">
<label  for="sName">Party 1's surname</label>
<input  type="text"  name="sName" id="sName" placeholder="Enter surname"> 
<span class="message" id="SnameError"></span>
         <br>
</div>
<div>
<label> Phone number </label>
<input type="text" name="phoneno" maxlength="10" placeholder="Enter 8 digit phone number" value="04">
<span id="phonenoerror" ></span>
<br>
</div> 

</script>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...