2014-01-19 2 views
0

나는 html로 양식을 만들었으며 자바 스크립트를 사용하여 유효성을 검사했습니다. 첫 번째 이름과 아버지의 이름은 20자를 넘지 않아야합니다. 걔들은 일하고있어. 내 코드는 다음과 같습니다자바 스크립트의 양식 유효성 검사 (이벤트 처리)

<html> 
    <head> 
     <script type="text/javascript"> 
     function validate() 
     { 
      var firstName=document.f1.firname.value; 
      var fatherName=document.f1.fname.value; 
      var address=document.f1.add.value; 
      var phoneNumber=document.f1.ph.value; 
      var cnic=document.f1.cnic.value; 
      var email=document.f1.email.value; 
      var cgpa=document.f1.fname.value; 
      var sem=document.f1.sem.value; 
      var id=document.f1.cid.value; 
      if(firstName.length>20) 
      { 
       alert("Value can't exceed 20"); 
      } 
      if(fatherName.length>20) 
      { 
       alert("Value can't exceed 20"); 
      } 
     } 
     </script> 
    </head> 
    <body> 
    <form name="f1"> 
     Name : <input type="text",name="firname"> <br> 
     Father's Name: <input type="text",name="fname"> <br> 
     Address: <input type="text",name="add"> <br> 
     Phone No.:<input type="text",name="ph"> <br> 
     CNIC:<input type="text",name="cnic"> <br> 
     Email:<input type="text",name="email"> <br> 
     City :<br> <input type="radio" name="city" value="lhr"> Lahore <br> 
     <input type="radio" name="city" value="karachi"> Karachi <br> 
     <input type="radio" name="city" value="isl"> Islamabad <br> 
     <select name="country"> 
      <option value="pakistan">Pakistan</option> 
      <option value="india">India</option> 
      <option value="china">China</option> 
     </select> <br> 
     Cgpa:<input type="text",name="cgpa"> <br> 
     Department:<input type="text",name="dpt"> <br> 
     <select name="degree"> 
      <option value="se">SE</option> 
      <option value="cs">CS</option> 
      <option value="it">IT</option> 
     </select> <br> 
     Semester:<input type="text",name="sem"> <br> 
     CollegeId:<input type="text",name="cid"> <br> 
     <input type="Submit", value="Submit" ,onsubmit="validate()"> 
    </form> 
    </body> 

무슨 문제입니까?

+0

''이어야 ' – MichaelJames

+0

경고 팝업이 여전히 나타나지 않습니다 .. – Ahmed

답변

1

HTML 특성을 구분하는 데 쉼표를 사용하지 마십시오. 그것은해야한다 :

Name : <input type="text" name="firname"> <br> 

하지 :

Name : <input type="text",name="firname"> <br> 

onsubmit 이벤트 형태가 아닌 input 버튼해야한다.

<form name="f1" onsubmit="validate()"> 
+0

고맙습니다. – Ahmed

관련 문제