1

<head>
<title> Add User page</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<form name='f2' action="insert_ac.php" method="post" >
<script src="validation.js" type="javascript/text"></script> 
</head>
<body  onload="firstfocus();">
<table align="center" border="0" cellpadding="3" cellspacing="1">
 <tr>
 <td> First Name</td><td > : </td>
 <td>  <input type='text' name='fname' id='fid' size="50" style="background-color:#abcddd; height:18px;" value='' maxlength="100" onblur="fname_validation(5,12);">    </td>
  </tr>
 <tr>
<td> Last Name</td><td> : </td>
 <td> <input type='text' name='lname' id='lid' size="50" style="background-color:#abcddd; height:18px; "value='' maxlength="100" onblur="lname_validation(5,12);"> </td>
  </tr>
 <tr>
<td> Gender</td><td> : </td>
<td> <input type='radio' name='gend' id='m' value='M' checked>Male <input type='radio' name='gend' id='f' value='F'>Female</td>
</tr>
<tr>
<td> Phone Number</td><td> : </td>
 <td> <input type='number_format' name='phone' id='phno'size="50" style="background-color:#abcddd; height:18px; " value=''onblur="allnumeric();"></td>
 </tr>
  <tr>
  <td> Work Experiance</td><td> : </td>
   <td><select name="exp" onblur="expselect();">
   <option > Select One</option>
   <option selected="" value="Default"> Select One </option>
   <option value="F"> Fresher </option>
   <option value="E"> Experiance</option>
   </select></td>
   </tr>
   <tr>
   <td>User Name</td><td>:</td><td> <input type='txt' name='uname' id='uid'size="50" style="background-color:#abcddd; height:18px; " value=''onblur="userid_validation(5,10);">   </td>
   </tr>
    <tr>
   <td>Password</td><td>:</td><td> <input type='password' name='pwd' id='pid' size="50" style="background-color:#abcddd; height:18px; " value=''onblur="passid_validation(7,12);"></td>
   </tr>
  <tr>
 <td>&nbsp;</td>
  <td>&nbsp;</td>
 <td width="84"><input name="enter" class="btn_login" type="submit" value="Submit"  onsubmit="alert('Data stored successfully');"/>&nbsp;&nbsp;<input name="cancle" class="btn_login" type="reset" value="Cancle" /></td>
  </tr>
 </table>

 </form>
 </body>
 </html>

script タグを使用して外部 JavaScript ファイルを含めましたが、検証が機能しません。

これは、validation.js として保存された私の外部 JavaScript コードであり、エラーを見つけることができません。助けてください。

// After form loads focus will go to first name field.  
function firstfocus()  
{  
var fname = document.f2.fname.focus();  
return true;  
}  
// This function will validate First name  
function fname_validation(mx,my)  
{  
var fname = document.f2.fname;  
var fname_len = fname.value.length; 
var letters = /^[A-Za-z]+$/;  
 if (fname_len == 0 || fname_len >= my || fname_len < mx)  
{  
alert("First Name should not be empty / length be between "+mx+" to "+my);  
fname.focus();  
return false;  
      if(fname.value.match(letters)) 
    {  
// Focus goes to next field i.e.Last Name  
 document.f2.lname.focus();  
return true;  
 }  
}  
 }

 // This function will validate Last name  
function lname_validation(mx,my)  
 {  
 var lname = document.f2.lname;  
 var lname_len = lname.value.length; 
 var letters = /^[A-Za-z]+$/;    
 if (lname_len == 0 || lname_len >= my || lname_len < mx)  
 {  
  alert("Last Name should not be empty / length be between "+mx+" to "+my);  
  lname.focus();  
    return false;  
    if(fname.value.match(letters)) 
    {  
    // Focus goes to next field i.e.Phone Number  
     document.f2.phone.focus();  
   return true;  
   }  
   }  
   }

  // This function will validate Phone Number.  
  function allnumeric()  
   {   
   var phone = document.f2.phone;  
     var numbers = /^[0-9]+$/;  
     if(phone.value.match(numbers))  
     {  
    // Focus goes to next field i.e. Experiance.  
   document.f2.exp.focus();  
    return true;  
   }  
   else  
   {  
   alert('Phone Number must have numeric characters only');  
   phone.focus();  
   return false;  
   }  
   }    
   // This function will select Experiance.  
    function expselect()  
    {  
   var exp = document.f2.exp;  
   if(exp.value == "Default")  
   {  
   alert('Select your Experiance from the list');  
   exp.focus();  
   return false;  
   }  
   else  
   {  
   // Focus goes to next field i.e. Username Code.  
   document.f2.uname.focus();  
   return true;  
  }  
  }  

  // This function will validate User Name.  
  function allLetter()  
   {   
   var uname = document.f2.uname;  
   var letters = /^[A-Za-z]+$/;  
  if(uname.value.match(letters))  
   {  
   // Focus goes to next field i.e. Password.  
    document.f2.pwd.focus();  
     return true;  
    }  
    else  
     {  
     alert('Username must have alphabet characters only');  
    uname.focus();  
     return false;  
     }  
     }  

    // This function will validate Password.  
   function passid_validation(mx,my)  
   {  
   var passid = document.registration.passid;  
    var passid_len = passid.value.length;  
   if (passid_len == 0 ||passid_len >= my || passid_len < mx)  
    {  
    alert("Password should not be empty / length be between "+mx+" to "+my);  
     passid.focus();  
     return false;  
     }  
     }  
4

3 に答える 3