Loading
View RSS Feed

Angad Kumar Shukla's blog

Check Box and Radio Button validation using Javascript

Rating: 13 votes, 4.69 average.
HTML File :
Code:
<html>

<head>
 <title> add bank</title>
<center><u><b><font color="blue">NSEP BANK REGISTRATION FORM</font></b></u> </center>

<script type="text/javascript" src="validation.js">

</script>
</head>
<body>
<br /><br />
<form action="regsuccess.html" name="f" onsubmit="return validate()">
       <center> <h5>All mandatory fields are marked with <font                  color="red">*</font></h5></center>

    <div style="position:relative;top=30px;left=320px;"><font color="red">*</font> Bank                        
                                Name  &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp   &nbsp&nbsp&nbsp                              
                                                &nbsp&nbsp <input type="text" name="bn" maxlength="20">&nbsp<font size="0px"                                          
                                           color="red">(max 20 characters allowed)</font></div>

 <div style="position:relative;top=40px;left=320px;"><font  color="red">*</font>   
Nationalized  &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp   &nbsp&nbsp&nbsp  <input type="radio" name="tb" >Yes &nbsp<input type="radio" name="tb" >No</div>
     
       <div style="position:relative;top=50px;left=320px;"><font color="red">*</font> Branch Location &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp    &nbsp<select name="bl" >
<option value="N/A">-- select a location--</option>
<option>Kolkata 
<option>Mumbai
<option>Chennai 
<option>Delhi 
</select>
</div>
<div style="position:relative;top=60px;left=332px;"> SPOC Name &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp  &nbsp&nbsp&nbsp    &nbsp <input type="text" name="s" maxlength="20">&nbsp<font size="0px" color="red">(max 20 characters allowed)</font></div>
      

  <div style="position:relative;top=70px;left=332px;"> SPOC Number &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp  &nbsp&nbsp&nbsp<input type="text" name="scn" maxlength="10"></div>
    


  <div style="position:relative;top=80px;left=320px;"><font  color="red">*</font> Account Type&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp &nbsp <input type="checkbox" name="ac" value="sav">Savings    <input type="checkbox" name="ac" value="cur">  Current       <input type="checkbox" name="ac"  value="rec">Recurring  <input type="checkbox" name="ac" value="fxd">Fixed
    
</div>
 <div style="position:relative;top=100px;left=410px;">

  <input type="submit" name="submit" value="Submit">
&nbsp &nbsp  <input type="reset" name="reset" value="Reset">

</div>

</form>
</body>
<html>

Javascript File :
Code:
	function validate()
	{
		var x1=validateBank();
		var x2=validateLocation();
		var x3=validatenation();
		var v4=validateAccount();
		var v5=noaccount();
		if(x1==false || x2==false || x3==false || v4==false)
		return false;
else if (v5==false)
		{
noaccount();
return false;
	}
check_spocnum();
}
	function validateBank()
                   {
		var x=f.bn.value;
		if(x=="")
		{
                     		alert("Choose a Bank");
			return false;
                     	}
		else
			return true;	
                     }
	function validateLocation()
	{
		var x1=f.bl.value;
		if(x1=="N/A")
		{
			alert("choose a specific location");
			return false;
		}
		else 
			return true;
	}
	function validateAccount()
	{
		var v="";
		var flag=false;
		for(var i=0; i<f.ac.length; i++)
		{
			var v=f.ac[i].checked;
			if(v==true)  
				{
				flag=true;
				break;
				}
		}
		if(flag==false)
		{
			alert("Choose account type");
			return false;
		}
		else
			return true;
	}
function validatenation()
{

if ( ( f.tb[0].checked == false ) && ( f.tb[1].checked == false ) )
	 { 
		alert("choose nationalized");
	return false;
	 }
else
	return true;
}
function noaccount()
{
var v="";
		var fl=0;

	
		for(var i=0; i<f.ac.length; i++)
		{
			var v=f.ac[i].checked;
			if(v==true)  
				{
				fl++;
			
				}
		}
if ( ( f.tb[0].checked == true )  )
{
		if(fl<2)
		{
			alert("Choose atleast 2 account type");
		return false;
		}
}
}
function check_spocnum()
{
  

   var val=f.scn.value;
   var len=val.length;
   var flag=true;
  
   if(len!=10)
           flag=false;
   else
         for(var indx=0;indx<val.length;indx++)
        {
                  if(val.charAt(indx)<'0'||val.charAt(indx)>'9')
                  {
                            flag=false;
                            break;
                  }
         }
         if(flag==true)
          {
   
              return true;
          }
        
         else
        {
             alert("spoc must be 10 digits long & consist of numbers only");
                return false;
       }
     }

Submit "Check Box and  Radio Button validation using Javascript" to Digg Submit "Check Box and  Radio Button validation using Javascript" to del.icio.us Submit "Check Box and  Radio Button validation using Javascript" to StumbleUpon Submit "Check Box and  Radio Button validation using Javascript" to Google

Comments




Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.