2010-10-07 101 views
0

我有以下代碼來執行下面顯示的SubmitForm驗證。當我單擊AddressListing div標記並調用驗證函數時,它僅對businessname字段執行驗證,但不對其他剩餘feilds.Only商業名稱字段將以紅色突出顯示,但不會顯示其他行爲。我使用下面的jQuery插件驗證領域http://jquery.bassistance.de/validate/jquery.validate.js使用jquery validate插件進行表單驗證的問題

example.html的

<fieldset id="fieldset1"> <legend>Registration Details:</legend> 
       <form id="SubmitForm"> 
       Name of business:<br/> 
        <input size="30" type="text" id="businessname" class="required" /><br/>    
       Zipcode:<br> 
        <input size="30" type="text" id="zipcode" class="required zipcode"/><br>    
       Telephone:<br/> 
        <input size="30" type="text" id="telephone" class="required phone" /><br/> 
       Email:<br/> 
        <input size="30" type="text" id="email" class="required email"/> 
        </fieldset> 
        <br/> 
       Your email is your User Name:<br/> 
       <input size="30" type="text" id="username" class="required"/><br/> 
       Choose Password:<br/> 
       <input size="30" type="text" id="pass" class="required password" class="required"/><br/> 
       Retype Password:<br/> 
       <input size="30" type="text" id="pass1" equalTo="#pass"/><br/>    
     <input id="Addresslisting" type="image" src="images/Submit.png" align="left" />         
    </form> 
</feildset> 

Example.js

$(document).ready(function() { 

    $("#Addresslisting").click(function() { 
    $("#addresslistingform").validate(); 
}); 

}); 

Example.css

label { width: 10em; float: left; } 
label.error { 

color: red; padding:8px 200px 0px 0px; vertical-align: top; float:right; 
background:url("unchecked.gif") no-repeat 120px 0px; 
    } 
input.error {border:1px solid red;} 
input.errorlist {margin:0; color: red; margin-bottom:10px;} 
#fieldset1 
{ 
border: 1px solid #1f76c8; 
width: 500px; 
margin:5px; 
padding:10px 15px 5px 15px; 
} 

回答

1

EDIT 2您缺少y上的名稱屬性我們的表單域。我有它在這裏工作:http://jsfiddle.net/3aPHy/

$(document).ready(function() { 

    $("#Addresslisting").click(function() { 
     $("#SubmitForm").validate(); 
    }); 

}); 

難道你不驗證錯了嗎?它不應該是submitForm嗎?

編輯如果上述不行,請嘗試:

$(document).ready(function() { 
    $("#SubmitForm").validate(); 

    $("#Addresslisting").click(function() { 
     $("#SubmitForm").submit(); 
    }); 
}); 
+0

我的表單的Id是SubmitForm我怎麼能寫submitForm,S和F都在大寫 – mahesh 2010-10-07 11:38:29

+0

錯誤...所以我的代碼示例。你嘗試過其中之一嗎? – Gazler 2010-10-07 11:41:03

+0

對不起,謝謝你的答覆,這實際上是我的錯誤 – mahesh 2010-10-07 11:44:42

0

試試這個:

$().ready(function() 
    { 
     // validate signup form on keyup and submit 
     $("#SubmitForm").validate(); 
    } 

我不知道郵政編碼已經存在於你所需要的規則默認明確地在驗證規則中定義它

rules: { 
zip: {  required:true, 
      maxlength:6, 
      number:true 
     }, 
     }